Implemented a domain layer, because the API DTO's where getting bloated.
This commit is contained in:
+9
-40
@@ -3,17 +3,7 @@ use axum::{
|
||||
response::{IntoResponse, Response},
|
||||
};
|
||||
|
||||
use crate::routes::{
|
||||
dtos::{
|
||||
direction::DirectionConversionError,
|
||||
scheduled_transaction::RecurringTransactionConversionError,
|
||||
transaction::TransactionConversionError,
|
||||
},
|
||||
validation::{
|
||||
recurring_transaction::ScheduledTransactionValidationError,
|
||||
transaction::TransactionValidationError,
|
||||
},
|
||||
};
|
||||
use crate::{domain::ValidationError, repository::RepositoryError};
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum AppError {
|
||||
@@ -23,23 +13,11 @@ pub enum AppError {
|
||||
#[error("not found")]
|
||||
NotFound,
|
||||
|
||||
#[error("database error")]
|
||||
Database(#[from] sqlx::Error),
|
||||
#[error("repository error")]
|
||||
Repository(#[from] RepositoryError),
|
||||
|
||||
#[error("direction conversion error")]
|
||||
Direction(#[from] DirectionConversionError),
|
||||
|
||||
#[error("recurring transaction conversion error")]
|
||||
RecurringTransaction(#[from] RecurringTransactionConversionError),
|
||||
|
||||
#[error("transaction conversion error")]
|
||||
Transaction(#[from] TransactionConversionError),
|
||||
|
||||
#[error("scheduled transaction validation error")]
|
||||
ScheduledTransactionValidation(#[from] ScheduledTransactionValidationError),
|
||||
|
||||
#[error("transaction validation error")]
|
||||
TransactionValidation(#[from] TransactionValidationError),
|
||||
#[error("validation error")]
|
||||
Validation(#[from] ValidationError),
|
||||
}
|
||||
|
||||
impl IntoResponse for AppError {
|
||||
@@ -51,23 +29,14 @@ impl IntoResponse for AppError {
|
||||
Self::NotFound => {
|
||||
return error_response(StatusCode::NOT_FOUND, "Not found");
|
||||
}
|
||||
Self::ScheduledTransactionValidation(error) => {
|
||||
Self::Validation(error) => {
|
||||
return error_response(StatusCode::UNPROCESSABLE_ENTITY, error.to_string());
|
||||
}
|
||||
Self::TransactionValidation(error) => {
|
||||
return error_response(StatusCode::UNPROCESSABLE_ENTITY, error.to_string());
|
||||
}
|
||||
Self::Database(error) => {
|
||||
Self::Repository(RepositoryError::Database(error)) => {
|
||||
tracing::error!(%error, "Database query failed");
|
||||
}
|
||||
Self::Direction(error) => {
|
||||
tracing::error!(%error, "Invalid transaction direction")
|
||||
}
|
||||
Self::RecurringTransaction(error) => {
|
||||
tracing::error!(%error, "Invalid recurring transaction data")
|
||||
}
|
||||
Self::Transaction(error) => {
|
||||
tracing::error!(%error, "Invalid transaction data");
|
||||
Self::Repository(RepositoryError::Decode(error)) => {
|
||||
tracing::error!(%error, "Invalid stored data");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user