Moved some errors around.
This commit is contained in:
+12
-12
@@ -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,
|
||||
|
||||
|
||||
@@ -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)?;
|
||||
|
||||
+12
-12
@@ -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(),
|
||||
|
||||
@@ -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)?;
|
||||
|
||||
@@ -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)?;
|
||||
|
||||
Reference in New Issue
Block a user