| use axum::{http::StatusCode, response::IntoResponse, Json}; |
| use serde_json::json; |
| use thiserror::Error; |
|
|
| #[derive(Debug, Error)] |
| pub enum MarisError { |
| #[error("Iekšēja kļūda: {0}")] |
| Internal(String), |
| #[error("Derīguma kļūda: {0}")] |
| Validation(String), |
| #[error("Nav atrasts: {0}")] |
| NotFound(String), |
| #[error("Python bridge kļūda: {0}")] |
| Bridge(String), |
| } |
|
|
| impl IntoResponse for MarisError { |
| fn into_response(self) -> axum::response::Response { |
| let (status, msg) = match &self { |
| MarisError::Internal(m) => (StatusCode::INTERNAL_SERVER_ERROR, m.clone()), |
| MarisError::Validation(m) => (StatusCode::BAD_REQUEST, m.clone()), |
| MarisError::NotFound(m) => (StatusCode::NOT_FOUND, m.clone()), |
| MarisError::Bridge(m) => (StatusCode::BAD_GATEWAY, m.clone()), |
| }; |
| (status, Json(json!({ "error": msg }))).into_response() |
| } |
| } |
|
|