use axum::{ http::StatusCode, response::{IntoResponse, Response}, Json, }; use serde_json::json; pub enum AppError { Generic, Database, } impl IntoResponse for AppError { fn into_response(self) -> Response { let (status, error_message) = match self { AppError::Generic => ( StatusCode::INTERNAL_SERVER_ERROR, "Generic error, can't find why", ), AppError::Database => ( StatusCode::INTERNAL_SERVER_ERROR, "Error with database connection", ), }; let body = Json(json!({ "error": error_message, })); (status, body).into_response() } } impl From for AppError { fn from(_error: sqlx::Error) -> AppError { AppError::Database } }