feature/upstream-service #13
@@ -1,3 +1,4 @@
|
||||
use axum::response::IntoResponse;
|
||||
use sea_orm::DbErr;
|
||||
|
||||
#[derive(Debug)]
|
||||
@@ -37,3 +38,23 @@ impl From<DbErr> for ServiceError {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoResponse for ServiceError {
|
||||
fn into_response(self) -> axum::response::Response {
|
||||
let (status, message) = match &self {
|
||||
ServiceError::NotFound(msg) => (axum::http::StatusCode::NOT_FOUND, msg.clone()),
|
||||
ServiceError::DatabaseError(msg) => {
|
||||
(axum::http::StatusCode::INTERNAL_SERVER_ERROR, msg.clone())
|
||||
}
|
||||
ServiceError::Unauthorized(msg) => (axum::http::StatusCode::UNAUTHORIZED, msg.clone()),
|
||||
ServiceError::InternalError(msg) => {
|
||||
(axum::http::StatusCode::INTERNAL_SERVER_ERROR, msg.clone())
|
||||
}
|
||||
ServiceError::BadRequest(msg) => (axum::http::StatusCode::BAD_REQUEST, msg.clone()),
|
||||
};
|
||||
let body = axum::Json(serde_json::json!({
|
||||
"error": message,
|
||||
}));
|
||||
(status, body).into_response()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user