Skip to content

Commit

Permalink
make authorization errors more explicit
Browse files Browse the repository at this point in the history
  • Loading branch information
lucat1 committed Dec 28, 2023
1 parent 10982eb commit 8f55b35
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions server/src/api/extract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ pub struct TypedHeader<T>(pub T);

#[derive(Debug, Error)]
pub enum TypedHeaderError {
#[error("Could not get typed header")]
#[error("Could not get typed header: {}", .0)]
TypedHeader(#[from] TypedHeaderRejection),
}

Expand Down Expand Up @@ -205,7 +205,7 @@ pub enum ClaimsError {
#[error("Could not get the settings")]
Settings(#[from] SettingsError),

#[error("Could not get typed header")]
#[error("Missing Authorization header")]
TypedHeader(#[from] TypedHeaderError),

#[error("Invalid authentication token")]
Expand All @@ -214,8 +214,12 @@ pub enum ClaimsError {

impl IntoResponse for ClaimsError {
fn into_response(self) -> Response {
let status = match self {
ClaimsError::Settings(_) => StatusCode::INTERNAL_SERVER_ERROR,
_ => StatusCode::UNAUTHORIZED,
};
Error {
status: StatusCode::BAD_REQUEST,
status,
title: self.to_string(),
detail: match self {
ClaimsError::Settings(e) => Some(Box::new(e)),
Expand Down

0 comments on commit 8f55b35

Please sign in to comment.