diff options
Diffstat (limited to 'src/error.rs')
-rw-r--r-- | src/error.rs | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/src/error.rs b/src/error.rs index f143ee9..1592a78 100644 --- a/src/error.rs +++ b/src/error.rs | |||
@@ -10,19 +10,20 @@ use crate::auth::AuthError; | |||
10 | #[derive(Debug)] | 10 | #[derive(Debug)] |
11 | pub enum WebolError { | 11 | pub enum WebolError { |
12 | Generic, | 12 | Generic, |
13 | // User(UserError), | ||
13 | Auth(AuthError), | 14 | Auth(AuthError), |
14 | Ping(surge_ping::SurgeError), | 15 | Ping(surge_ping::SurgeError), |
15 | DB(sqlx::Error), | 16 | DB(sqlx::Error), |
16 | IpParse(<std::net::IpAddr as std::str::FromStr>::Err), | 17 | IpParse(<std::net::IpAddr as std::str::FromStr>::Err), |
17 | BufferParse(std::num::ParseIntError), | 18 | BufferParse(std::num::ParseIntError), |
18 | Broadcast(io::Error), | 19 | Broadcast(io::Error), |
19 | Axum(axum::Error) | ||
20 | } | 20 | } |
21 | 21 | ||
22 | impl IntoResponse for WebolError { | 22 | impl IntoResponse for WebolError { |
23 | fn into_response(self) -> Response { | 23 | fn into_response(self) -> Response { |
24 | let (status, error_message) = match self { | 24 | let (status, error_message) = match self { |
25 | Self::Auth(err) => err.get(), | 25 | Self::Auth(err) => err.get(), |
26 | // Self::User(err) => err.get(), | ||
26 | Self::Generic => (StatusCode::INTERNAL_SERVER_ERROR, ""), | 27 | Self::Generic => (StatusCode::INTERNAL_SERVER_ERROR, ""), |
27 | Self::Ping(err) => { | 28 | Self::Ping(err) => { |
28 | error!("Ping: {}", err.source().unwrap()); | 29 | error!("Ping: {}", err.source().unwrap()); |
@@ -44,10 +45,6 @@ impl IntoResponse for WebolError { | |||
44 | error!("server error: {}", err.to_string()); | 45 | error!("server error: {}", err.to_string()); |
45 | (StatusCode::INTERNAL_SERVER_ERROR, "Server Error") | 46 | (StatusCode::INTERNAL_SERVER_ERROR, "Server Error") |
46 | }, | 47 | }, |
47 | Self::Axum(err) => { | ||
48 | error!("server error: {}", err.to_string()); | ||
49 | (StatusCode::INTERNAL_SERVER_ERROR, "Server Error") | ||
50 | }, | ||
51 | }; | 48 | }; |
52 | let body = Json(json!({ | 49 | let body = Json(json!({ |
53 | "error": error_message, | 50 | "error": error_message, |
@@ -55,3 +52,16 @@ impl IntoResponse for WebolError { | |||
55 | (status, body).into_response() | 52 | (status, body).into_response() |
56 | } | 53 | } |
57 | } | 54 | } |
55 | |||
56 | // #[derive(Debug)] | ||
57 | // pub enum UserError { | ||
58 | // UnknownUUID, | ||
59 | // } | ||
60 | // | ||
61 | // impl UserError { | ||
62 | // pub fn get(self) -> (StatusCode, &'static str) { | ||
63 | // match self { | ||
64 | // Self::UnknownUUID => (StatusCode::UNPROCESSABLE_ENTITY, "Unknown UUID"), | ||
65 | // } | ||
66 | // } | ||
67 | // } | ||