File size: 929 Bytes
f440f03 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | 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()
}
}
|