From 3e6a72428824c5a50a873a4284b86d0a9e47a778 Mon Sep 17 00:00:00 2001 From: fx Date: Mon, 9 Oct 2023 17:26:59 +0200 Subject: db int for api --- src/error.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/error.rs (limited to 'src/error.rs') 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 @@ +use std::error::Error; +use axum::http::StatusCode; +use axum::Json; +use axum::response::{IntoResponse, Response}; +use serde_json::json; +use tracing::error; +use crate::auth::AuthError; + +pub enum WebolError { + Auth(AuthError), + Generic, + Server(Box), +} + +impl IntoResponse for WebolError { + fn into_response(self) -> Response { + let (status, error_message) = match self { + WebolError::Auth(err) => err.get(), + WebolError::Generic => (StatusCode::INTERNAL_SERVER_ERROR, ""), + WebolError::Server(err) => { + error!("server error: {}", err.to_string()); + (StatusCode::INTERNAL_SERVER_ERROR, "Server Error") + }, + + }; + let body = Json(json!({ + "error": error_message, + })); + (status, body).into_response() + } +} -- cgit v1.2.3