feat: retry networking errors (#64)

Co-authored-by: Jeffrey Dallatezza <jeffreydallatezza@Jeffreys-Laptop.local>
reqwest-12
Jeffrey Dallatezza 2024-03-06 12:32:07 -08:00 committed by GitHub
parent c5810076fc
commit 181403c578
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 22 additions and 4 deletions

View File

@ -57,10 +57,28 @@ impl RegionalRequester {
.send(); .send();
#[cfg(feature = "tracing")] #[cfg(feature = "tracing")]
let request_clone = request_clone.instrument(tracing::info_span!("request")); let request_clone = request_clone.instrument(tracing::info_span!("request"));
let response = request_clone let response = request_clone.await;
.await let response = match response {
.map_err(|e| RiotApiError::new(e, retries, None, None))?; Ok(response) => response,
// Check for lower level errors, like connection errors.
Err(e) => {
if retries >= config.retries {
log::debug!(
"Request failed (retried {} times), failure, returning error.",
retries
);
break Err(RiotApiError::new(e, retries, None, None));
}
let delay = Duration::from_secs(2_u64.pow(retries as u32));
log::debug!("Request failed with cause \"{}\", (retried {} times), using exponential backoff, retrying after {:?}.", e.to_string(), retries, delay);
let backoff = sleep(delay);
#[cfg(feature = "tracing")]
let backoff = backoff.instrument(tracing::info_span!("backoff"));
backoff.await;
retries += 1;
continue;
}
};
// Maybe update rate limits (based on response headers). // Maybe update rate limits (based on response headers).
// Use single bar for no short circuiting. // Use single bar for no short circuiting.
let retry_after_app = self.app_rate_limit.on_response(config, &response); let retry_after_app = self.app_rate_limit.on_response(config, &response);