push progress
This commit is contained in:
parent
752c885c10
commit
c6ded56510
|
@ -1,9 +1,12 @@
|
|||
pub mod register {
|
||||
use reqwest::Client;
|
||||
use serde_json::json;
|
||||
use serde_json::{from_str, json};
|
||||
|
||||
use crate::{
|
||||
api::{limits::LimitType, schemas::schemas::RegisterSchema},
|
||||
api::{
|
||||
limits::LimitType,
|
||||
schemas::schemas::{ErrorBody, RegisterSchema},
|
||||
},
|
||||
errors::InstanceServerError,
|
||||
instance::{Instance, Token},
|
||||
};
|
||||
|
@ -30,16 +33,24 @@ pub mod register {
|
|||
.await;
|
||||
if response.is_none() {
|
||||
return Err(InstanceServerError::NoResponse);
|
||||
} else {
|
||||
// temp
|
||||
return Err(InstanceServerError::NoResponse);
|
||||
} // end temp
|
||||
}
|
||||
|
||||
let response_unwrap = response.unwrap();
|
||||
let status = response_unwrap.status();
|
||||
let response_text_string = response_unwrap.text().await.unwrap();
|
||||
if status.is_client_error() {
|
||||
let error: ErrorBody = from_str(&response_text_string).unwrap();
|
||||
return Err(InstanceServerError::InvalidFormBodyError {
|
||||
error: error.errors.errors.iter().next().unwrap().code.clone(),
|
||||
});
|
||||
}
|
||||
return Ok(Token {
|
||||
token: response_text_string,
|
||||
});
|
||||
|
||||
/*
|
||||
Things to do:
|
||||
1. Check the response for Errors. If the Response says the request is missing a field,
|
||||
return an Err() that says that.
|
||||
|
||||
Check out the serde error. Maybe make a seperate project to find out how flatten works
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
|
|
@ -150,6 +150,24 @@ pub mod schemas {
|
|||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct ErrorBody {
|
||||
code: i32,
|
||||
pub message: String,
|
||||
pub errors: ErrorObject,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct ErrorObject {
|
||||
#[serde(flatten)]
|
||||
pub errors: Vec<Error>,
|
||||
}
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct Error {
|
||||
pub message: String,
|
||||
pub code: String,
|
||||
}
|
||||
}
|
||||
|
||||
// I know that some of these tests are... really really basic and unneccessary, but sometimes, I
|
||||
|
|
|
@ -6,7 +6,7 @@ custom_error! {
|
|||
PasswordError = "Password must be between 1 and 72 characters.",
|
||||
UsernameError = "Username must be between 2 and 32 characters.",
|
||||
ConsentError = "Consent must be 'true' to register.",
|
||||
EmailError = "The provided email address is in an invalid format."
|
||||
EmailError = "The provided email address is in an invalid format.",
|
||||
}
|
||||
|
||||
custom_error! {
|
||||
|
@ -15,5 +15,6 @@ custom_error! {
|
|||
NoResponse = "Did not receive a response from the Server.",
|
||||
RequestErrorError{url:String, error:String} = "An error occured while trying to GET from {url}: {error}",
|
||||
ReceivedErrorCodeError{error_code:String} = "Received the following error code while requesting from the route: {error_code}",
|
||||
CantGetInfoError{error:String} = "Something seems to be wrong with the instance. Cannot get information about the instance: {error}"
|
||||
CantGetInfoError{error:String} = "Something seems to be wrong with the instance. Cannot get information about the instance: {error}",
|
||||
InvalidFormBodyError{error:String} = "The server responded with: {error}",
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue