Skip to content

Commit

Permalink
fix: prevent panic on StatusCode conversion
Browse files Browse the repository at this point in the history
http_types::StatusCode doesn't support all status codes that http::StatusCode supports, but still implements From<http::StatusCode>, just with an `unwrap`. This is unfortunate because it can cause the client to panic upon responses that contain status codes not explicitly supported by http_types.
  • Loading branch information
FSMaxB committed Oct 4, 2023
1 parent 16fced0 commit 9b94228
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/client/base/tokio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,12 @@ async fn send_inner(
StripeError::from(e.error)
})
.unwrap_or_else(StripeError::from);
last_status = Some(status.into());
last_status = Some(
// NOTE: StatusCode::from can panic here, so fall back to InternalServerError
// see https://github.com/http-rs/http-types/blob/ac5d645ce5294554b86ebd49233d3ec01665d1d7/src/hyperium_http.rs#L20-L24
StatusCode::try_from(u16::from(status))
.unwrap_or(StatusCode::InternalServerError),
);
last_retry_header = retry;
continue;
}
Expand Down

0 comments on commit 9b94228

Please sign in to comment.