aboutsummaryrefslogtreecommitdiff
path: root/src/error.rs
diff options
context:
space:
mode:
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}