2022-10-02 20:51:06 +02:00
|
|
|
use axum::{http::StatusCode, response::IntoResponse, Json};
|
|
|
|
use serde_json::json;
|
|
|
|
|
2023-09-05 22:05:17 +02:00
|
|
|
#[allow(dead_code)]
|
2022-10-02 20:51:06 +02:00
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum AppError {
|
|
|
|
WrongCredentials,
|
|
|
|
InternalServerError,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl IntoResponse for AppError {
|
|
|
|
fn into_response(self) -> axum::response::Response {
|
|
|
|
let (status, err_msg) = match self {
|
|
|
|
Self::WrongCredentials => (StatusCode::BAD_REQUEST, "invalid credentials"),
|
|
|
|
Self::InternalServerError => (
|
|
|
|
StatusCode::INTERNAL_SERVER_ERROR,
|
|
|
|
"something went wrong with your request",
|
|
|
|
),
|
|
|
|
};
|
|
|
|
(status, Json(json!({ "error": err_msg }))).into_response()
|
|
|
|
}
|
|
|
|
}
|