push progress
This commit is contained in:
parent
752c885c10
commit
c6ded56510
|
@ -1,9 +1,12 @@
|
||||||
pub mod register {
|
pub mod register {
|
||||||
use reqwest::Client;
|
use reqwest::Client;
|
||||||
use serde_json::json;
|
use serde_json::{from_str, json};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
api::{limits::LimitType, schemas::schemas::RegisterSchema},
|
api::{
|
||||||
|
limits::LimitType,
|
||||||
|
schemas::schemas::{ErrorBody, RegisterSchema},
|
||||||
|
},
|
||||||
errors::InstanceServerError,
|
errors::InstanceServerError,
|
||||||
instance::{Instance, Token},
|
instance::{Instance, Token},
|
||||||
};
|
};
|
||||||
|
@ -30,16 +33,24 @@ pub mod register {
|
||||||
.await;
|
.await;
|
||||||
if response.is_none() {
|
if response.is_none() {
|
||||||
return Err(InstanceServerError::NoResponse);
|
return Err(InstanceServerError::NoResponse);
|
||||||
} else {
|
}
|
||||||
// temp
|
|
||||||
return Err(InstanceServerError::NoResponse);
|
let response_unwrap = response.unwrap();
|
||||||
} // end temp
|
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:
|
Things to do:
|
||||||
1. Check the response for Errors. If the Response says the request is missing a field,
|
Check out the serde error. Maybe make a seperate project to find out how flatten works
|
||||||
return an Err() that says that.
|
|
||||||
|
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
// 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.",
|
PasswordError = "Password must be between 1 and 72 characters.",
|
||||||
UsernameError = "Username must be between 2 and 32 characters.",
|
UsernameError = "Username must be between 2 and 32 characters.",
|
||||||
ConsentError = "Consent must be 'true' to register.",
|
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! {
|
custom_error! {
|
||||||
|
@ -15,5 +15,6 @@ custom_error! {
|
||||||
NoResponse = "Did not receive a response from the Server.",
|
NoResponse = "Did not receive a response from the Server.",
|
||||||
RequestErrorError{url:String, error:String} = "An error occured while trying to GET from {url}: {error}",
|
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}",
|
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