mirror of
https://github.com/TrueLayer/reqwest-middleware.git
synced 2024-12-27 03:16:32 +00:00
added some comments
This commit is contained in:
parent
161eb5a2af
commit
fce3ea6d7e
1 changed files with 6 additions and 0 deletions
|
@ -50,7 +50,12 @@ impl Retryable {
|
|||
{
|
||||
Some(Retryable::Fatal)
|
||||
} else if error.is_request() {
|
||||
// It seems that hyper::Error(IncompleteMessage) is not correctly handled by reqwest.
|
||||
// Here we check if the Reqwest error was originated by hyper and map it consistently.
|
||||
if let Some(hyper_error) = get_source_error_type::<hyper::Error>(&error) {
|
||||
// The hyper::Error(IncompleteMessage) is raised if the HTTP response is well formatted but does not contain all the bytes.
|
||||
// This can happen when the server has started sending back the response but the connection is cut halfway thorugh.
|
||||
// We can safely retry the call, hence marking this error as [`Retryable::Transient`].
|
||||
if hyper_error.is_incomplete_message() {
|
||||
Some(Retryable::Transient)
|
||||
} else {
|
||||
|
@ -77,6 +82,7 @@ impl From<&reqwest::Error> for Retryable {
|
|||
}
|
||||
}
|
||||
|
||||
/// Downcasts the given [`err`] source into [`T`].
|
||||
fn get_source_error_type<T: std::error::Error + 'static>(
|
||||
err: &dyn std::error::Error,
|
||||
) -> Option<&T> {
|
||||
|
|
Loading…
Reference in a new issue