Skip to content

Commit

Permalink
add permission denied error type
Browse files Browse the repository at this point in the history
  • Loading branch information
t-aleksander committed Jun 6, 2024
1 parent 5271e76 commit d061f06
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ pub enum ApiError {
CoreTimeout,
#[error("Invalid core gRPC response type received")]
InvalidResponseType,
#[error("PermissionDenied")]
PermissionDenied,
}

impl IntoResponse for ApiError {
Expand All @@ -30,6 +32,7 @@ impl IntoResponse for ApiError {
let (status, error_message) = match self {
Self::Unauthorized => (StatusCode::UNAUTHORIZED, self.to_string()),
Self::BadRequest(msg) => (StatusCode::BAD_REQUEST, msg),
Self::PermissionDenied => (StatusCode::FORBIDDEN, self.to_string()),
_ => (
StatusCode::INTERNAL_SERVER_ERROR,
"Internal server error".to_string(),
Expand All @@ -51,6 +54,7 @@ impl From<CoreError> for ApiError {
match status.code() {
Code::Unauthenticated => ApiError::Unauthorized,
Code::InvalidArgument => ApiError::BadRequest(status.message().to_string()),
Code::PermissionDenied => ApiError::PermissionDenied,
_ => ApiError::Unexpected(status.to_string()),
}
}
Expand Down

0 comments on commit d061f06

Please sign in to comment.