From 05492123d711ae25d49a77ef50be7fcb52673fe1 Mon Sep 17 00:00:00 2001 From: Rogier Reerink Date: Mon, 12 Oct 2026 17:18:32 +0200 Subject: [PATCH] Moved some errors around. --- server/src/error.rs | 24 ++++++++++----------- server/src/routes/account_members.rs | 2 +- server/src/routes/errors.rs | 24 ++++++++++----------- server/src/routes/scheduled_transactions.rs | 2 +- server/src/routes/transactions.rs | 2 +- 5 files changed, 27 insertions(+), 27 deletions(-) diff --git a/server/src/error.rs b/server/src/error.rs index 06c697c..1874bdf 100644 --- a/server/src/error.rs +++ b/server/src/error.rs @@ -2,27 +2,27 @@ use crate::{domain::DomainError, repository::RepositoryError, routes::extractors #[derive(Debug, thiserror::Error)] pub enum AppError { + #[error("account not found")] + AccountNotFound, + + #[error("user not found")] + UserNotFound, + #[error("account id already exists")] AccountIdAlreadyExists, - #[error("account id not found")] - AccountIdNotFound, - - #[error("transaction id already exists")] - TransactionIdAlreadyExists, - - #[error("scheduled transaction id already exists")] - ScheduledTransactionIdAlreadyExists, - #[error("app id already exists")] AppIdAlreadyExists, + #[error("scheduled transaction id already exists")] + ScheduledTransactionIdAlreadyExists, + + #[error("transaction id already exists")] + TransactionIdAlreadyExists, + #[error("cannot remove the last member of an account")] LastAccountMemberRemoval, - #[error("user id not found")] - UserIdNotFound, - #[error("invalid client credentials")] InvalidClientCredentials, diff --git a/server/src/routes/account_members.rs b/server/src/routes/account_members.rs index dbd5ffb..e0cb266 100644 --- a/server/src/routes/account_members.rs +++ b/server/src/routes/account_members.rs @@ -95,7 +95,7 @@ async fn upsert_account_member( let member = member.into_domain(member_id, account_id)?; let user = repository::users::get_by_id(&pool, member.user_id) .await? - .ok_or(AppError::UserIdNotFound)?; + .ok_or(AppError::UserNotFound)?; let upserted = repository::account_members::upsert(&pool, user_id, member) .await? .ok_or(AppError::NotFound)?; diff --git a/server/src/routes/errors.rs b/server/src/routes/errors.rs index d6ebbce..3918b81 100644 --- a/server/src/routes/errors.rs +++ b/server/src/routes/errors.rs @@ -25,29 +25,29 @@ impl IntoResponse for AppError { impl ClientError for AppError { fn client_response(&self) -> (StatusCode, Cow<'_, str>) { match self { + Self::AccountNotFound => ( + StatusCode::UNPROCESSABLE_ENTITY, + "Account cannot be found".into(), + ), + Self::UserNotFound => ( + StatusCode::UNPROCESSABLE_ENTITY, + "User cannot be found".into(), + ), Self::AccountIdAlreadyExists => { (StatusCode::CONFLICT, "Account ID already exists".into()) } - Self::AccountIdNotFound => ( - StatusCode::UNPROCESSABLE_ENTITY, - "Account ID cannot be found".into(), - ), - Self::TransactionIdAlreadyExists => { - (StatusCode::CONFLICT, "Transaction ID already exists".into()) - } + Self::AppIdAlreadyExists => (StatusCode::CONFLICT, "App ID already exists".into()), Self::ScheduledTransactionIdAlreadyExists => ( StatusCode::CONFLICT, "Scheduled transaction ID already exists".into(), ), - Self::AppIdAlreadyExists => (StatusCode::CONFLICT, "App ID already exists".into()), + Self::TransactionIdAlreadyExists => { + (StatusCode::CONFLICT, "Transaction ID already exists".into()) + } Self::LastAccountMemberRemoval => ( StatusCode::CONFLICT, "Cannot remove the last member of an account".into(), ), - Self::UserIdNotFound => ( - StatusCode::UNPROCESSABLE_ENTITY, - "User ID cannot be found".into(), - ), Self::InvalidClientCredentials => ( StatusCode::UNAUTHORIZED, "Invalid client credentials".into(), diff --git a/server/src/routes/scheduled_transactions.rs b/server/src/routes/scheduled_transactions.rs index 24a0977..00f3417 100644 --- a/server/src/routes/scheduled_transactions.rs +++ b/server/src/routes/scheduled_transactions.rs @@ -94,7 +94,7 @@ async fn upsert_scheduled_transaction( let transaction = transaction.into_domain(id)?; let account = repository::accounts::get_by_id(&pool, user_id, transaction.account_id) .await? - .ok_or(AppError::AccountIdNotFound)?; + .ok_or(AppError::AccountNotFound)?; let upserted = repository::recurring_transactions::upsert(&pool, user_id, transaction) .await? .ok_or(AppError::ScheduledTransactionIdAlreadyExists)?; diff --git a/server/src/routes/transactions.rs b/server/src/routes/transactions.rs index 0838349..e329070 100644 --- a/server/src/routes/transactions.rs +++ b/server/src/routes/transactions.rs @@ -88,7 +88,7 @@ async fn upsert_transaction( let transaction = transaction.into_domain(id)?; let account = repository::accounts::get_by_id(&pool, user_id, transaction.account_id) .await? - .ok_or(AppError::AccountIdNotFound)?; + .ok_or(AppError::AccountNotFound)?; let upserted = repository::transactions::upsert(&pool, user_id, transaction) .await? .ok_or(AppError::TransactionIdAlreadyExists)?;