Cleaned up errors a bit.

This commit is contained in:
2026-09-26 21:26:46 +02:00
parent 75ee0cb760
commit 67153c79bb
8 changed files with 59 additions and 63 deletions
+7 -7
View File
@@ -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")