aboutsummaryrefslogtreecommitdiff
path: root/src/error.rs
diff options
context:
space:
mode:
authorfx <[email protected]>2023-10-09 17:26:59 +0200
committerfx <[email protected]>2023-10-09 17:26:59 +0200
commit3e6a72428824c5a50a873a4284b86d0a9e47a778 (patch)
tree7f3594f4068a8009210039bc33e0205a672828f7 /src/error.rs
parent732c487d3dab4af9fc561527591d3d56299e39f2 (diff)
downloadwebol-3e6a72428824c5a50a873a4284b86d0a9e47a778.tar
webol-3e6a72428824c5a50a873a4284b86d0a9e47a778.tar.gz
webol-3e6a72428824c5a50a873a4284b86d0a9e47a778.zip
db int for api
Diffstat (limited to 'src/error.rs')
-rw-r--r--src/error.rs31
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 @@
1use std::error::Error;
2use axum::http::StatusCode;
3use axum::Json;
4use axum::response::{IntoResponse, Response};
5use serde_json::json;
6use tracing::error;
7use crate::auth::AuthError;
8
9pub enum WebolError {
10 Auth(AuthError),
11 Generic,
12 Server(Box<dyn Error>),
13}
14
15impl 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}