diff options
author | FxQnLr <[email protected]> | 2023-11-06 11:09:34 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2023-11-06 11:09:34 +0100 |
commit | 1cd2a8e4aecfaad2a8385a6bea61580209b86398 (patch) | |
tree | c357bcaca0681caf9a6742c857bb494dc4315900 /src/error.rs | |
parent | d9d7b125e4fcaa3aedd7b57a69e6880e012ccf33 (diff) | |
parent | 32561060a8dc6fc6118498da06bdd8f5b4c3f0fd (diff) | |
download | webol-1cd2a8e4aecfaad2a8385a6bea61580209b86398.tar webol-1cd2a8e4aecfaad2a8385a6bea61580209b86398.tar.gz webol-1cd2a8e4aecfaad2a8385a6bea61580209b86398.zip |
Merge pull request #6 from FxQnLr/ping
Ping
Diffstat (limited to 'src/error.rs')
-rw-r--r-- | src/error.rs | 32 |
1 files changed, 24 insertions, 8 deletions
diff --git a/src/error.rs b/src/error.rs index db2fc86..5b82534 100644 --- a/src/error.rs +++ b/src/error.rs | |||
@@ -1,4 +1,4 @@ | |||
1 | use std::error::Error; | 1 | use std::io; |
2 | use axum::http::StatusCode; | 2 | use axum::http::StatusCode; |
3 | use axum::Json; | 3 | use axum::Json; |
4 | use axum::response::{IntoResponse, Response}; | 4 | use axum::response::{IntoResponse, Response}; |
@@ -8,25 +8,41 @@ use crate::auth::AuthError; | |||
8 | 8 | ||
9 | #[derive(Debug)] | 9 | #[derive(Debug)] |
10 | pub enum WebolError { | 10 | pub enum WebolError { |
11 | Auth(AuthError), | ||
12 | Generic, | 11 | Generic, |
13 | Server(Box<dyn Error>), | 12 | Auth(AuthError), |
13 | DB(sqlx::Error), | ||
14 | IpParse(<std::net::IpAddr as std::str::FromStr>::Err), | ||
15 | BufferParse(std::num::ParseIntError), | ||
16 | Broadcast(io::Error), | ||
14 | } | 17 | } |
15 | 18 | ||
16 | impl IntoResponse for WebolError { | 19 | impl IntoResponse for WebolError { |
17 | fn into_response(self) -> Response { | 20 | fn into_response(self) -> Response { |
18 | let (status, error_message) = match self { | 21 | let (status, error_message) = match self { |
19 | WebolError::Auth(err) => err.get(), | 22 | Self::Auth(err) => { |
20 | WebolError::Generic => (StatusCode::INTERNAL_SERVER_ERROR, ""), | 23 | err.get() |
21 | WebolError::Server(err) => { | 24 | }, |
25 | Self::Generic => (StatusCode::INTERNAL_SERVER_ERROR, ""), | ||
26 | Self::IpParse(err) => { | ||
27 | error!("server error: {}", err.to_string()); | ||
28 | (StatusCode::INTERNAL_SERVER_ERROR, "Server Error") | ||
29 | }, | ||
30 | Self::DB(err) => { | ||
31 | error!("server error: {}", err.to_string()); | ||
32 | (StatusCode::INTERNAL_SERVER_ERROR, "Server Error") | ||
33 | }, | ||
34 | Self::Broadcast(err) => { | ||
35 | error!("server error: {}", err.to_string()); | ||
36 | (StatusCode::INTERNAL_SERVER_ERROR, "Server Error") | ||
37 | }, | ||
38 | Self::BufferParse(err) => { | ||
22 | error!("server error: {}", err.to_string()); | 39 | error!("server error: {}", err.to_string()); |
23 | (StatusCode::INTERNAL_SERVER_ERROR, "Server Error") | 40 | (StatusCode::INTERNAL_SERVER_ERROR, "Server Error") |
24 | }, | 41 | }, |
25 | |||
26 | }; | 42 | }; |
27 | let body = Json(json!({ | 43 | let body = Json(json!({ |
28 | "error": error_message, | 44 | "error": error_message, |
29 | })); | 45 | })); |
30 | (status, body).into_response() | 46 | (status, body).into_response() |
31 | } | 47 | } |
32 | } | 48 | } \ No newline at end of file |