pub type Result = std::result::Result; #[derive(thiserror::Error, Debug)] pub enum Error { #[error(transparent)] IO(#[from] std::io::Error), #[error(transparent)] TaskJoin(#[from] tokio::task::JoinError), #[error(transparent)] Axum(#[from] axum::Error), #[error(transparent)] Sqlx(#[from] sqlx::Error), #[error(transparent)] Migration(#[from] sqlx::migrate::MigrateError), #[error("User not found: {0}")] UserNotFound(uuid::Uuid), } impl axum::response::IntoResponse for Error { fn into_response(self) -> axum::response::Response { use axum::{http::StatusCode, Json}; use serde_json::json; match self { Error::UserNotFound(uuid) => ( StatusCode::BAD_REQUEST, Json(json!({ "status": "fail", "message": uuid, })), ), err => ( StatusCode::INTERNAL_SERVER_ERROR, Json(json!({ "error": err.to_string(), })), ), } .into_response() } }