use axum::response::{IntoResponse, Response}; use http::StatusCode; use sea_orm::DbErr; use tracing::log::error; #[derive(thiserror::Error, Debug)] pub enum AppError { /// SeaORM error, separated for ease of use allowing us to `?` db operations. #[error("Internal error")] DbError(#[from] DbErr), #[error("Invalid request {0}")] BadRequest(anyhow::Error), /// Catch all for error we dont care to expose publicly. #[error("Internal error")] Anyhow(#[from] anyhow::Error), } impl IntoResponse for AppError { fn into_response(self) -> Response { error!("Internal server error: {self:?}"); let status_code = match self { _ => StatusCode::INTERNAL_SERVER_ERROR, }; (status_code, self.to_string()).into_response() } }