diff options
author | fx <[email protected]> | 2023-10-09 17:26:59 +0200 |
---|---|---|
committer | fx <[email protected]> | 2023-10-09 17:26:59 +0200 |
commit | 3e6a72428824c5a50a873a4284b86d0a9e47a778 (patch) | |
tree | 7f3594f4068a8009210039bc33e0205a672828f7 /src/error.rs | |
parent | 732c487d3dab4af9fc561527591d3d56299e39f2 (diff) | |
download | webol-3e6a72428824c5a50a873a4284b86d0a9e47a778.tar webol-3e6a72428824c5a50a873a4284b86d0a9e47a778.tar.gz webol-3e6a72428824c5a50a873a4284b86d0a9e47a778.zip |
db int for api
Diffstat (limited to 'src/error.rs')
-rw-r--r-- | src/error.rs | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/error.rs b/src/error.rs new file mode 100644 index 0000000..afed111 --- /dev/null +++ b/src/error.rs | |||
@@ -0,0 +1,31 @@ | |||
1 | use std::error::Error; | ||
2 | use axum::http::StatusCode; | ||
3 | use axum::Json; | ||
4 | use axum::response::{IntoResponse, Response}; | ||
5 | use serde_json::json; | ||
6 | use tracing::error; | ||
7 | use crate::auth::AuthError; | ||
8 | |||
9 | pub enum WebolError { | ||
10 | Auth(AuthError), | ||
11 | Generic, | ||
12 | Server(Box<dyn Error>), | ||
13 | } | ||
14 | |||
15 | impl IntoResponse for WebolError { | ||
16 | fn into_response(self) -> Response { | ||
17 | let (status, error_message) = match self { | ||
18 | WebolError::Auth(err) => err.get(), | ||
19 | WebolError::Generic => (StatusCode::INTERNAL_SERVER_ERROR, ""), | ||
20 | WebolError::Server(err) => { | ||
21 | error!("server error: {}", err.to_string()); | ||
22 | (StatusCode::INTERNAL_SERVER_ERROR, "Server Error") | ||
23 | }, | ||
24 | |||
25 | }; | ||
26 | let body = Json(json!({ | ||
27 | "error": error_message, | ||
28 | })); | ||
29 | (status, body).into_response() | ||
30 | } | ||
31 | } | ||