Cleaned up errors a bit.
This commit is contained in:
+7
-7
@@ -3,7 +3,7 @@ use axum::{
|
||||
response::{IntoResponse, Response},
|
||||
};
|
||||
|
||||
use crate::{domain::ValidationError, repository::RepositoryError};
|
||||
use crate::{domain::DomainError, repository::RepositoryError};
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum AppError {
|
||||
@@ -13,11 +13,11 @@ pub enum AppError {
|
||||
#[error("not found")]
|
||||
NotFound,
|
||||
|
||||
#[error("domain error")]
|
||||
Domain(#[from] DomainError),
|
||||
|
||||
#[error("repository error")]
|
||||
Repository(#[from] RepositoryError),
|
||||
|
||||
#[error("validation error")]
|
||||
Validation(#[from] ValidationError),
|
||||
}
|
||||
|
||||
impl IntoResponse for AppError {
|
||||
@@ -29,6 +29,9 @@ impl IntoResponse for AppError {
|
||||
Self::NotFound => {
|
||||
return error_response(StatusCode::NOT_FOUND, "Not found");
|
||||
}
|
||||
Self::Domain(error) => {
|
||||
return error_response(StatusCode::UNPROCESSABLE_ENTITY, error.to_string());
|
||||
}
|
||||
Self::Repository(RepositoryError::Database(error)) => {
|
||||
tracing::error!(%error, "Database query failed");
|
||||
}
|
||||
@@ -38,9 +41,6 @@ impl IntoResponse for AppError {
|
||||
Self::Repository(RepositoryError::QueryConversion(error)) => {
|
||||
return error_response(StatusCode::BAD_REQUEST, error.to_string());
|
||||
}
|
||||
Self::Validation(error) => {
|
||||
return error_response(StatusCode::UNPROCESSABLE_ENTITY, error.to_string());
|
||||
}
|
||||
}
|
||||
|
||||
error_response(StatusCode::INTERNAL_SERVER_ERROR, "Internal server error")
|
||||
|
||||
Reference in New Issue
Block a user