use std::fmt::Display; use axum::{Json, http::StatusCode, response::IntoResponse}; use serde::Serialize; #[derive(Debug)] pub struct AppError { inner: anyhow::Error, } impl Display for AppError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.inner) } } impl From for AppError where E: Into, { fn from(err: E) -> Self { Self { inner: err.into() } } } #[derive(Serialize)] struct ErrorBody { error: String, } impl IntoResponse for AppError { fn into_response(self) -> axum::response::Response { ( StatusCode::INTERNAL_SERVER_ERROR, Json(ErrorBody { error: self.inner.to_string(), }), ) .into_response() } } pub type AppResult = Result;