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)]
|
#[derive(Debug, thiserror::Error)]
|
||||||
pub enum AppError {
|
pub enum AppError {
|
||||||
|
#[error("account not found")]
|
||||||
|
AccountNotFound,
|
||||||
|
|
||||||
|
#[error("user not found")]
|
||||||
|
UserNotFound,
|
||||||
|
|
||||||
#[error("account id already exists")]
|
#[error("account id already exists")]
|
||||||
AccountIdAlreadyExists,
|
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")]
|
#[error("app id already exists")]
|
||||||
AppIdAlreadyExists,
|
AppIdAlreadyExists,
|
||||||
|
|
||||||
|
#[error("scheduled transaction id already exists")]
|
||||||
|
ScheduledTransactionIdAlreadyExists,
|
||||||
|
|
||||||
|
#[error("transaction id already exists")]
|
||||||
|
TransactionIdAlreadyExists,
|
||||||
|
|
||||||
#[error("cannot remove the last member of an account")]
|
#[error("cannot remove the last member of an account")]
|
||||||
LastAccountMemberRemoval,
|
LastAccountMemberRemoval,
|
||||||
|
|
||||||
#[error("user id not found")]
|
|
||||||
UserIdNotFound,
|
|
||||||
|
|
||||||
#[error("invalid client credentials")]
|
#[error("invalid client credentials")]
|
||||||
InvalidClientCredentials,
|
InvalidClientCredentials,
|
||||||
|
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ async fn upsert_account_member(
|
|||||||
let member = member.into_domain(member_id, account_id)?;
|
let member = member.into_domain(member_id, account_id)?;
|
||||||
let user = repository::users::get_by_id(&pool, member.user_id)
|
let user = repository::users::get_by_id(&pool, member.user_id)
|
||||||
.await?
|
.await?
|
||||||
.ok_or(AppError::UserIdNotFound)?;
|
.ok_or(AppError::UserNotFound)?;
|
||||||
let upserted = repository::account_members::upsert(&pool, user_id, member)
|
let upserted = repository::account_members::upsert(&pool, user_id, member)
|
||||||
.await?
|
.await?
|
||||||
.ok_or(AppError::NotFound)?;
|
.ok_or(AppError::NotFound)?;
|
||||||
|
|||||||
+12
-12
@@ -25,29 +25,29 @@ impl IntoResponse for AppError {
|
|||||||
impl ClientError for AppError {
|
impl ClientError for AppError {
|
||||||
fn client_response(&self) -> (StatusCode, Cow<'_, str>) {
|
fn client_response(&self) -> (StatusCode, Cow<'_, str>) {
|
||||||
match self {
|
match self {
|
||||||
|
Self::AccountNotFound => (
|
||||||
|
StatusCode::UNPROCESSABLE_ENTITY,
|
||||||
|
"Account cannot be found".into(),
|
||||||
|
),
|
||||||
|
Self::UserNotFound => (
|
||||||
|
StatusCode::UNPROCESSABLE_ENTITY,
|
||||||
|
"User cannot be found".into(),
|
||||||
|
),
|
||||||
Self::AccountIdAlreadyExists => {
|
Self::AccountIdAlreadyExists => {
|
||||||
(StatusCode::CONFLICT, "Account ID already exists".into())
|
(StatusCode::CONFLICT, "Account ID already exists".into())
|
||||||
}
|
}
|
||||||
Self::AccountIdNotFound => (
|
Self::AppIdAlreadyExists => (StatusCode::CONFLICT, "App ID already exists".into()),
|
||||||
StatusCode::UNPROCESSABLE_ENTITY,
|
|
||||||
"Account ID cannot be found".into(),
|
|
||||||
),
|
|
||||||
Self::TransactionIdAlreadyExists => {
|
|
||||||
(StatusCode::CONFLICT, "Transaction ID already exists".into())
|
|
||||||
}
|
|
||||||
Self::ScheduledTransactionIdAlreadyExists => (
|
Self::ScheduledTransactionIdAlreadyExists => (
|
||||||
StatusCode::CONFLICT,
|
StatusCode::CONFLICT,
|
||||||
"Scheduled transaction ID already exists".into(),
|
"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 => (
|
Self::LastAccountMemberRemoval => (
|
||||||
StatusCode::CONFLICT,
|
StatusCode::CONFLICT,
|
||||||
"Cannot remove the last member of an account".into(),
|
"Cannot remove the last member of an account".into(),
|
||||||
),
|
),
|
||||||
Self::UserIdNotFound => (
|
|
||||||
StatusCode::UNPROCESSABLE_ENTITY,
|
|
||||||
"User ID cannot be found".into(),
|
|
||||||
),
|
|
||||||
Self::InvalidClientCredentials => (
|
Self::InvalidClientCredentials => (
|
||||||
StatusCode::UNAUTHORIZED,
|
StatusCode::UNAUTHORIZED,
|
||||||
"Invalid client credentials".into(),
|
"Invalid client credentials".into(),
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ async fn upsert_scheduled_transaction(
|
|||||||
let transaction = transaction.into_domain(id)?;
|
let transaction = transaction.into_domain(id)?;
|
||||||
let account = repository::accounts::get_by_id(&pool, user_id, transaction.account_id)
|
let account = repository::accounts::get_by_id(&pool, user_id, transaction.account_id)
|
||||||
.await?
|
.await?
|
||||||
.ok_or(AppError::AccountIdNotFound)?;
|
.ok_or(AppError::AccountNotFound)?;
|
||||||
let upserted = repository::recurring_transactions::upsert(&pool, user_id, transaction)
|
let upserted = repository::recurring_transactions::upsert(&pool, user_id, transaction)
|
||||||
.await?
|
.await?
|
||||||
.ok_or(AppError::ScheduledTransactionIdAlreadyExists)?;
|
.ok_or(AppError::ScheduledTransactionIdAlreadyExists)?;
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ async fn upsert_transaction(
|
|||||||
let transaction = transaction.into_domain(id)?;
|
let transaction = transaction.into_domain(id)?;
|
||||||
let account = repository::accounts::get_by_id(&pool, user_id, transaction.account_id)
|
let account = repository::accounts::get_by_id(&pool, user_id, transaction.account_id)
|
||||||
.await?
|
.await?
|
||||||
.ok_or(AppError::AccountIdNotFound)?;
|
.ok_or(AppError::AccountNotFound)?;
|
||||||
let upserted = repository::transactions::upsert(&pool, user_id, transaction)
|
let upserted = repository::transactions::upsert(&pool, user_id, transaction)
|
||||||
.await?
|
.await?
|
||||||
.ok_or(AppError::TransactionIdAlreadyExists)?;
|
.ok_or(AppError::TransactionIdAlreadyExists)?;
|
||||||
|
|||||||
Reference in New Issue
Block a user