These errors have become app level errors.

This commit is contained in:
2026-10-09 15:28:27 +02:00
parent 66984567f8
commit 18e142ec91
4 changed files with 11 additions and 40 deletions
+7 -24
View File
@@ -13,6 +13,9 @@ pub enum AppError {
#[error("bad request")]
BadRequest(String),
#[error("conflict")]
Conflict(String),
#[error("not found")]
NotFound,
@@ -36,6 +39,10 @@ impl IntoResponse for AppError {
tracing::debug!(%error, "bad request");
return error_response(StatusCode::BAD_REQUEST, error);
}
Self::Conflict(error) => {
tracing::warn!(%error, "conflict");
return error_response(StatusCode::CONFLICT, error);
}
Self::NotFound => {
tracing::debug!("not found");
return error_response(StatusCode::NOT_FOUND, "Not found");
@@ -54,30 +61,6 @@ impl IntoResponse for AppError {
Self::Repository(RepositoryError::Decode(error)) => {
tracing::error!(%error, "invalid stored data");
}
Self::Repository(RepositoryError::NotFound {
relation: ReferenceRelation::User,
}) => {
tracing::debug!("user not found");
return error_response(StatusCode::NOT_FOUND, "User cannot be found");
}
Self::Repository(RepositoryError::NotFound {
relation: ReferenceRelation::UserApp,
}) => {
tracing::debug!("user app not found");
return error_response(StatusCode::NOT_FOUND, "User app cannot be found");
}
Self::Repository(RepositoryError::NotFound { relation }) => {
tracing::error!(%relation, "unhandled not found");
}
Self::Repository(RepositoryError::OwnershipConflict {
relation: ReferenceRelation::UserApp,
}) => {
tracing::warn!("user app ownership conflict");
return error_response(StatusCode::CONFLICT, "User app ID is already in use");
}
Self::Repository(RepositoryError::OwnershipConflict { relation }) => {
tracing::error!(%relation, "unhandled ownership conflict");
}
Self::Repository(RepositoryError::ReferenceViolation {
relation: ReferenceRelation::User,
kind: ReferenceViolationKind::Missing,
-6
View File
@@ -21,12 +21,6 @@ pub enum RepositoryError {
#[error(transparent)]
Decode(#[from] DecodeError),
#[error("{relation} cannot be found")]
NotFound { relation: ReferenceRelation },
#[error("{relation} is owned by another user")]
OwnershipConflict { relation: ReferenceRelation },
#[error("reference violation ({kind}: {relation})")]
ReferenceViolation {
relation: ReferenceRelation,
+2 -5
View File
@@ -13,7 +13,7 @@ use crate::{
crypto::{generate_secret, hash_secret},
domain::UserAppSecret,
error::AppError,
repository::{self, ReferenceRelation, RepositoryError},
repository::{self, RepositoryError},
};
pub fn create_router() -> axum::Router<PgPool> {
@@ -141,9 +141,6 @@ async fn ensure_app_ownership(
) -> Result<(), AppError> {
match repository::user_apps::find_owner_by_id(&mut *connection, app_id).await? {
Some(owner) if owner == user_id => Ok(()),
Some(_) | None => Err(RepositoryError::NotFound {
relation: ReferenceRelation::UserApp,
}
.into()),
Some(_) | None => Err(AppError::NotFound).into(),
}
}
+2 -5
View File
@@ -9,7 +9,7 @@ use super::{
};
use crate::{
error::AppError,
repository::{self, ReferenceRelation, RepositoryError},
repository::{self, RepositoryError},
};
pub fn create_router() -> axum::Router<PgPool> {
@@ -81,10 +81,7 @@ async fn upsert_user_app(
.as_ref()
.is_some_and(|previous| previous.user_id != user_id)
{
return Err(RepositoryError::OwnershipConflict {
relation: ReferenceRelation::UserApp,
}
.into());
return Err(AppError::Conflict("User app ID is already in use".into()).into());
}
tx.commit().await.map_err(RepositoryError::from)?;