parent
d3cdcea0df
commit
9aca4cadf0
13 changed files with 483 additions and 21 deletions
16
src/error.rs
16
src/error.rs
|
|
@ -32,16 +32,20 @@ pub enum AppError {
|
|||
|
||||
impl IntoResponse for AppError {
|
||||
fn into_response(self) -> Response {
|
||||
let (status, error_message) = match self {
|
||||
let (status, error_message) = match &self {
|
||||
AppError::Database(err) => (StatusCode::INTERNAL_SERVER_ERROR, err.to_string()),
|
||||
AppError::Config(err) => (StatusCode::INTERNAL_SERVER_ERROR, err),
|
||||
AppError::NotFound(err) => (StatusCode::NOT_FOUND, err),
|
||||
AppError::Unauthorized(err) => (StatusCode::UNAUTHORIZED, err),
|
||||
AppError::Internal(err) => (StatusCode::INTERNAL_SERVER_ERROR, err),
|
||||
AppError::Config(err) => (StatusCode::INTERNAL_SERVER_ERROR, err.clone()),
|
||||
AppError::NotFound(err) => (StatusCode::NOT_FOUND, err.clone()),
|
||||
AppError::Unauthorized(err) => (StatusCode::UNAUTHORIZED, err.clone()),
|
||||
AppError::Internal(err) => (StatusCode::INTERNAL_SERVER_ERROR, err.clone()),
|
||||
AppError::Network(err) => (StatusCode::BAD_GATEWAY, err.to_string()),
|
||||
AppError::InvalidRequest(err) => (StatusCode::BAD_REQUEST, err),
|
||||
AppError::InvalidRequest(err) => (StatusCode::BAD_REQUEST, err.clone()),
|
||||
};
|
||||
|
||||
if status.is_server_error() || status.is_client_error() {
|
||||
tracing::error!(%status, error = %self, "AppError converted to response");
|
||||
}
|
||||
|
||||
let body = Json(json!({
|
||||
"error": error_message,
|
||||
}));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue