feat: Enhance error handling by adding Forbidden and Unknown error types

This commit is contained in:
2025-11-15 17:29:58 +01:00
parent a9805b5eb1
commit 3f96de117b
3 changed files with 25 additions and 11 deletions

View File

@@ -22,6 +22,11 @@ impl IntoResponse for ApiError {
),
CoreError::Duplicate(e) => (StatusCode::CONFLICT, e),
CoreError::Auth(e) => (StatusCode::UNAUTHORIZED, e),
CoreError::Forbidden(e) => (StatusCode::FORBIDDEN, e),
CoreError::Unknown(e) => (
StatusCode::INTERNAL_SERVER_ERROR,
format!("An unknown error occurred: {}", e),
),
_ => (
StatusCode::INTERNAL_SERVER_ERROR,
"An unknown error occurred".to_string(),

View File

@@ -149,9 +149,15 @@ impl AuthorizationService for AuthorizationServiceImpl {
}
}
Err(CoreError::Auth(
"User does not have permission to view this media.".into(),
))
if user_id.is_some() {
return Err(CoreError::Forbidden(
"User does not have permission to view this media.".into(),
));
} else {
return Err(CoreError::Auth(
"Authentication required for this action".into(),
));
}
}
Permission::DeleteMedia(media_id) | Permission::EditMedia(media_id) => {
@@ -163,7 +169,7 @@ impl AuthorizationService for AuthorizationServiceImpl {
return Ok(());
}
Err(CoreError::Auth(
Err(CoreError::Forbidden(
"User does not have permission to modify this media.".into(),
))
}
@@ -189,7 +195,7 @@ impl AuthorizationService for AuthorizationServiceImpl {
return Ok(());
}
Err(CoreError::Auth(
Err(CoreError::Forbidden(
"User does not have permission to modify tags for this media.".into(),
))
}
@@ -206,7 +212,7 @@ impl AuthorizationService for AuthorizationServiceImpl {
return Ok(());
}
Err(CoreError::Auth(
Err(CoreError::Forbidden(
"User does not have permission to view this album.".into(),
))
}
@@ -222,7 +228,7 @@ impl AuthorizationService for AuthorizationServiceImpl {
return Ok(());
}
Err(CoreError::Auth(
Err(CoreError::Forbidden(
"User does not have permission to modify this album.".into(),
))
}
@@ -237,7 +243,7 @@ impl AuthorizationService for AuthorizationServiceImpl {
return Ok(());
}
Err(CoreError::Auth(
Err(CoreError::Forbidden(
"User does not have permission to share or delete this album.".into(),
))
}
@@ -253,7 +259,7 @@ impl AuthorizationService for AuthorizationServiceImpl {
return Ok(());
}
Err(CoreError::Auth(
Err(CoreError::Forbidden(
"User does not have permission to view this person.".into(),
))
}
@@ -270,7 +276,7 @@ impl AuthorizationService for AuthorizationServiceImpl {
return Ok(());
}
Err(CoreError::Auth(
Err(CoreError::Forbidden(
"User does not have permission to modify this person.".into(),
))
}
@@ -286,7 +292,7 @@ impl AuthorizationService for AuthorizationServiceImpl {
return Ok(());
}
Err(CoreError::Auth(
Err(CoreError::Forbidden(
"User does not have permission to use this person.".into(),
))
}