Skip to content

Commit

Permalink
Merge pull request #3 from IT-Finance-Flow-GmbH/21-change-http-resons…
Browse files Browse the repository at this point in the history
…e-codes

Changed response codes in error case
  • Loading branch information
Tockra authored Apr 12, 2024
2 parents 8aae71a + d412eba commit 3693891
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,13 @@ impl IntoResponse for AuthError {
Cow::Owned(err.to_string()),
),
err @ AuthError::MissingAuthorizationHeader => {
(StatusCode::BAD_REQUEST, Cow::Owned(err.to_string()))
(StatusCode::UNAUTHORIZED, Cow::Owned(err.to_string()))
}
err @ AuthError::InvalidAuthorizationHeader { reason: _ } => {
(StatusCode::BAD_REQUEST, Cow::Owned(err.to_string()))
(StatusCode::UNAUTHORIZED, Cow::Owned(err.to_string()))
}
err @ AuthError::MissingBearerToken => {
(StatusCode::BAD_REQUEST, Cow::Owned(err.to_string()))
(StatusCode::UNAUTHORIZED, Cow::Owned(err.to_string()))
}
err @ AuthError::CreateDecodingKey { source: _ } => (
StatusCode::INTERNAL_SERVER_ERROR,
Expand All @@ -134,14 +134,12 @@ impl IntoResponse for AuthError {
StatusCode::INTERNAL_SERVER_ERROR,
Cow::Owned(err.to_string()),
),
err @ AuthError::NoDecodingKeys => (
StatusCode::INTERNAL_SERVER_ERROR,
Cow::Owned(err.to_string()),
),
err @ AuthError::Decode { source: _ } => (
StatusCode::INTERNAL_SERVER_ERROR,
Cow::Owned(err.to_string()),
),
err @ AuthError::NoDecodingKeys => {
(StatusCode::UNAUTHORIZED, Cow::Owned(err.to_string()))
}
err @ AuthError::Decode { source: _ } => {
(StatusCode::UNAUTHORIZED, Cow::Owned(err.to_string()))
}
err @ AuthError::JsonParse { source: _ } => (
StatusCode::INTERNAL_SERVER_ERROR,
Cow::Owned(err.to_string()),
Expand All @@ -150,18 +148,16 @@ impl IntoResponse for AuthError {
(StatusCode::UNAUTHORIZED, Cow::Owned(err.to_string()))
}
err @ AuthError::InvalidToken { reason: _ } => {
(StatusCode::BAD_REQUEST, Cow::Owned(err.to_string()))
(StatusCode::UNAUTHORIZED, Cow::Owned(err.to_string()))
}
AuthError::MissingExpectedRole { role } => (
StatusCode::UNAUTHORIZED,
StatusCode::FORBIDDEN,
match cfg!(debug_assertions) {
true => Cow::Owned(format!("Missing expected role: {role}")),
false => Cow::Borrowed("Missing expected role"),
},
),
err @ AuthError::UnexpectedRole => {
(StatusCode::UNAUTHORIZED, Cow::Owned(err.to_string()))
}
err @ AuthError::UnexpectedRole => (StatusCode::FORBIDDEN, Cow::Owned(err.to_string())),
};
let body = Json(json!({
"error": error_message,
Expand Down

0 comments on commit 3693891

Please sign in to comment.