Treat not found as app error at API boundry.
This commit is contained in:
+9
-3
@@ -36,18 +36,24 @@ pub enum AppError {
|
|||||||
impl IntoResponse for AppError {
|
impl IntoResponse for AppError {
|
||||||
fn into_response(self) -> Response {
|
fn into_response(self) -> Response {
|
||||||
match self {
|
match self {
|
||||||
Self::NotFound => return StatusCode::NOT_FOUND.into_response(),
|
Self::NotFound => {
|
||||||
|
return StatusCode::NOT_FOUND.into_response();
|
||||||
|
}
|
||||||
Self::ScheduledTransactionValidation(error) => {
|
Self::ScheduledTransactionValidation(error) => {
|
||||||
return (StatusCode::UNPROCESSABLE_ENTITY, error.to_string()).into_response();
|
return (StatusCode::UNPROCESSABLE_ENTITY, error.to_string()).into_response();
|
||||||
}
|
}
|
||||||
Self::Database(error) => tracing::error!(%error, "Database query failed"),
|
Self::Database(error) => {
|
||||||
|
tracing::error!(%error, "Database query failed");
|
||||||
|
}
|
||||||
Self::Direction(error) => {
|
Self::Direction(error) => {
|
||||||
tracing::error!(%error, "Invalid transaction direction")
|
tracing::error!(%error, "Invalid transaction direction")
|
||||||
}
|
}
|
||||||
Self::RecurringTransaction(error) => {
|
Self::RecurringTransaction(error) => {
|
||||||
tracing::error!(%error, "Invalid recurring transaction data")
|
tracing::error!(%error, "Invalid recurring transaction data")
|
||||||
}
|
}
|
||||||
Self::Transaction(error) => tracing::error!(%error, "Invalid transaction data"),
|
Self::Transaction(error) => {
|
||||||
|
tracing::error!(%error, "Invalid transaction data");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
(StatusCode::INTERNAL_SERVER_ERROR, "Internal server error").into_response()
|
(StatusCode::INTERNAL_SERVER_ERROR, "Internal server error").into_response()
|
||||||
|
|||||||
@@ -102,8 +102,8 @@ async fn delete_scheduled_transaction(
|
|||||||
State(pool): State<PgPool>,
|
State(pool): State<PgPool>,
|
||||||
Path(id): Path<Uuid>,
|
Path(id): Path<Uuid>,
|
||||||
) -> Result<StatusCode, AppError> {
|
) -> Result<StatusCode, AppError> {
|
||||||
Ok(match delete_scheduled_transaction_by_id(&pool, id).await? {
|
match delete_scheduled_transaction_by_id(&pool, id).await? {
|
||||||
Delete::Deleted => StatusCode::NO_CONTENT,
|
Delete::Deleted => Ok(StatusCode::NO_CONTENT),
|
||||||
Delete::NotFound => StatusCode::NOT_FOUND,
|
Delete::NotFound => Err(AppError::NotFound),
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user