Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
akorchyn committed Nov 12, 2024
1 parent d6693c4 commit 77942dd
Showing 1 changed file with 29 additions and 23 deletions.
52 changes: 29 additions & 23 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,31 +225,37 @@ impl JsonRpcClient {
match response.status() {
reqwest::StatusCode::OK => {}
non_ok_status => {
return Err(JsonRpcError::ServerError(
match non_ok_status {
reqwest::StatusCode::UNAUTHORIZED => {
JsonRpcServerError::ResponseStatusError(JsonRpcServerResponseStatusError::Unauthorized)
}
reqwest::StatusCode::TOO_MANY_REQUESTS => {
JsonRpcServerError::ResponseStatusError(JsonRpcServerResponseStatusError::TooManyRequests)
}
reqwest::StatusCode::BAD_REQUEST => {
JsonRpcServerError::ResponseStatusError(JsonRpcServerResponseStatusError::BadRequest)
}
reqwest::StatusCode::INTERNAL_SERVER_ERROR => {
JsonRpcServerError::InternalError { info: Some(String::from("Internal server error")) }
}
reqwest::StatusCode::SERVICE_UNAVAILABLE => {
JsonRpcServerError::ResponseStatusError(JsonRpcServerResponseStatusError::ServiceUnavailable)
}
reqwest::StatusCode::REQUEST_TIMEOUT => {
JsonRpcServerError::ResponseStatusError(JsonRpcServerResponseStatusError::TimeoutError)
}
unexpected => {
JsonRpcServerError::ResponseStatusError(JsonRpcServerResponseStatusError::Unexpected { status: unexpected })
return Err(JsonRpcError::ServerError(match non_ok_status {
reqwest::StatusCode::UNAUTHORIZED => JsonRpcServerError::ResponseStatusError(
JsonRpcServerResponseStatusError::Unauthorized,
),
reqwest::StatusCode::TOO_MANY_REQUESTS => {
JsonRpcServerError::ResponseStatusError(
JsonRpcServerResponseStatusError::TooManyRequests,
)
}
reqwest::StatusCode::BAD_REQUEST => JsonRpcServerError::ResponseStatusError(
JsonRpcServerResponseStatusError::BadRequest,
),
reqwest::StatusCode::INTERNAL_SERVER_ERROR => {
JsonRpcServerError::InternalError {
info: Some(String::from("Internal server error")),
}
}
));
reqwest::StatusCode::SERVICE_UNAVAILABLE => {
JsonRpcServerError::ResponseStatusError(
JsonRpcServerResponseStatusError::ServiceUnavailable,
)
}
reqwest::StatusCode::REQUEST_TIMEOUT => {
JsonRpcServerError::ResponseStatusError(
JsonRpcServerResponseStatusError::TimeoutError,
)
}
unexpected => JsonRpcServerError::ResponseStatusError(
JsonRpcServerResponseStatusError::Unexpected { status: unexpected },
),
}));
}
}
let response_payload = response.bytes().await.map_err(|err| {
Expand Down

0 comments on commit 77942dd

Please sign in to comment.