Made scheduled transactions more generic.
This commit is contained in:
+18
-7
@@ -3,12 +3,16 @@ use axum::{
|
||||
response::{IntoResponse, Response},
|
||||
};
|
||||
|
||||
use crate::routes::dtos::expense::RecurringExpenseConversionError;
|
||||
use crate::routes::dtos::{
|
||||
direction::TransactionDirectionConversionError,
|
||||
scheduled_transaction::RecurringTransactionConversionError,
|
||||
};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum AppError {
|
||||
Database(sqlx::Error),
|
||||
RecurringExpense(RecurringExpenseConversionError),
|
||||
Direction(TransactionDirectionConversionError),
|
||||
RecurringTransaction(RecurringTransactionConversionError),
|
||||
}
|
||||
|
||||
impl From<sqlx::Error> for AppError {
|
||||
@@ -17,9 +21,15 @@ impl From<sqlx::Error> for AppError {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<RecurringExpenseConversionError> for AppError {
|
||||
fn from(error: RecurringExpenseConversionError) -> Self {
|
||||
Self::RecurringExpense(error)
|
||||
impl From<TransactionDirectionConversionError> for AppError {
|
||||
fn from(error: TransactionDirectionConversionError) -> Self {
|
||||
Self::Direction(error)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<RecurringTransactionConversionError> for AppError {
|
||||
fn from(error: RecurringTransactionConversionError) -> Self {
|
||||
Self::RecurringTransaction(error)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,8 +37,9 @@ impl IntoResponse for AppError {
|
||||
fn into_response(self) -> Response {
|
||||
match self {
|
||||
Self::Database(error) => tracing::error!(%error, "Database query failed"),
|
||||
Self::RecurringExpense(error) => {
|
||||
tracing::error!(%error, "Invalid recurring expense data")
|
||||
Self::Direction(error) => tracing::error!(%error, "Invalid transaction direction"),
|
||||
Self::RecurringTransaction(error) => {
|
||||
tracing::error!(%error, "Invalid recurring transaction data")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user