feat: add another rate limit retry check (#1881)

This commit is contained in:
Matthias Seitz 2022-11-22 22:08:04 +01:00 committed by GitHub
parent 616bd92cc4
commit 49dc487676
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 0 deletions

View File

@ -346,6 +346,12 @@ impl RetryPolicy<ClientError> for HttpRateLimitRetryPolicy {
if *code == 429 {
return true
}
// alternative alchemy error for specific IPs
if *code == -32016 && message.contains("rate limit") {
return true
}
match message.as_str() {
// this is commonly thrown by infura and is apparently a load balancer issue, see also <https://github.com/MetaMask/metamask-extension/issues/7234>
"header not found" => true,
@ -494,4 +500,14 @@ mod tests {
let backoff = HttpRateLimitRetryPolicy.backoff_hint(&err);
assert!(backoff.is_none());
}
#[test]
fn test_alchemy_ip_rate_limit() {
let s = "{\"code\":-32016,\"message\":\"Your IP has exceeded its requests per second capacity. To increase your rate limits, please sign up for a free Alchemy account at https://www.alchemy.com/optimism.\"}";
let err: JsonRpcError = serde_json::from_str(s).unwrap();
let err = ClientError::JsonRpcError(err);
let should_retry = HttpRateLimitRetryPolicy::default().should_retry(&err);
assert!(should_retry);
}
}