M sdbclient/src/api/mod.rs => sdbclient/src/api/mod.rs +15 -2
@@ 11,9 11,22 @@ use serde::{Deserialize, Serialize};
pub mod user;
-#[derive(Deserialize)]
+#[derive(Debug, Deserialize, Serialize)]
pub struct APIError {
- pub error: String,
+ pub id: u16,
+ pub name: String,
+ pub description: String,
+}
+
+#[derive(Debug, Deserialize, Serialize)]
+pub struct APIErrorWrapper {
+ pub error: APIError,
+}
+
+impl std::fmt::Display for APIErrorWrapper {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ write!(f, "{} {}", self.error.id, self.error.description)
+ }
}
#[derive(Serialize, Deserialize)]
M sdbclient/src/api/user/mod.rs => sdbclient/src/api/user/mod.rs +5 -3
@@ 9,6 9,8 @@
use reqwest;
use serde::{Deserialize, Serialize};
+use super::APIErrorWrapper;
+
#[derive(Serialize)]
pub struct PostToken {
pub email: String,
@@ 24,7 26,7 @@ pub struct ResultToken {
#[derive(Debug, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ResponseToken {
- Error { error: String },
+ Error(APIErrorWrapper),
Valid(ResultToken),
}
@@ 57,7 59,7 @@ pub struct ResultRegister {
#[derive(Debug, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ResponseRegister {
- Error { error: String },
+ Error(APIErrorWrapper),
Valid(ResultRegister),
}
@@ 92,7 94,7 @@ pub struct ResultUserInfoP {
#[derive(Debug, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ResponseUserInfoP {
- Error { error: String },
+ Error(APIErrorWrapper),
Valid(ResultUserInfoP),
}
M => +4 -5
@@ 84,8 84,7 @@ fn start_login_call(
res.id.clone(),
));
}
#[allow(unused_variables)]
ResponseToken::Error { error } => {}
ResponseToken::Error(_error) => {}
}
LoginCallResponse {
@@ 131,7 130,7 @@ fn handle_login_call(
login_state.set(LoginState::None).unwrap();
menu_state.set(MenuState::AccountLoggedIn).unwrap();
}
ResponseUserInfoP::Error { error } => {
ResponseUserInfoP::Error(error) => {
console.send(PrintConsoleLine::new(format!(
"Something went wrong with getting the user information after logging in, got error: '{}'", error
).into()));
@@ 141,8 140,8 @@ fn handle_login_call(
}
}
}
ResponseToken::Error { error } => {
inputs.error = error;
ResponseToken::Error(error) => {
inputs.error = error.error.description;
login_state.set(LoginState::Input).unwrap();
}
}
M => +3 -3
@@ 127,7 127,7 @@ fn handle_register_call(
register_state.set(RegisterState::None).unwrap();
menu_state.set(MenuState::AccountLoggedIn).unwrap();
}
ResponseToken::Error { error } => {
ResponseToken::Error(error) => {
// TODO: Handle? Is it possible to even get here without the server shitting itself between the register and token calls?
// And if the server does indeed shit itself between those calls, the user can just login normally, so 🤷♀️
console.send(PrintConsoleLine::new(format!(
@@ 139,8 139,8 @@ fn handle_register_call(
}
}
}
ResponseRegister::Error { error } => {
inputs.error = error;
ResponseRegister::Error(error) => {
inputs.error = error.error.description;
register_state.set(RegisterState::Input).unwrap();
}
}