Skip to content

Commit 9b94228

Browse files
committed
fix: prevent panic on StatusCode conversion
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.
1 parent 16fced0 commit 9b94228

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/client/base/tokio.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,12 @@ async fn send_inner(
160160
StripeError::from(e.error)
161161
})
162162
.unwrap_or_else(StripeError::from);
163-
last_status = Some(status.into());
163+
last_status = Some(
164+
// NOTE: StatusCode::from can panic here, so fall back to InternalServerError
165+
// see https://github.com/http-rs/http-types/blob/ac5d645ce5294554b86ebd49233d3ec01665d1d7/src/hyperium_http.rs#L20-L24
166+
StatusCode::try_from(u16::from(status))
167+
.unwrap_or(StatusCode::InternalServerError),
168+
);
164169
last_retry_header = retry;
165170
continue;
166171
}

0 commit comments

Comments
 (0)