Skip to content

Commit 36cbc4b

Browse files
Eras256claude
andcommitted
Fix shouldRetry not retrying QuickNode's -32007 rate-limit code
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
1 parent 86adf42 commit 36cbc4b

3 files changed

Lines changed: 24 additions & 0 deletions

File tree

.changeset/fix-quicknode-retry.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"viem": patch
3+
---
4+
5+
Fixed `shouldRetry` not retrying QuickNode's `-32007` rate-limit error code, mirroring the existing handling for the `429` (Alchemy) case.

src/utils/buildRequest.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1544,6 +1544,19 @@ describe('shouldRetry', () => {
15441544
expect(shouldRetry(err)).toBe(true)
15451545
})
15461546

1547+
test('RPC code -32007 (QuickNode rate limit)', () => {
1548+
// QuickNode returns its own rate-limit error as `{ code: -32007 }`
1549+
// rather than the standard `LimitExceededRpcError` code (`-32005`) or
1550+
// HTTP 429. shouldRetry must return true so that retryCount is honoured.
1551+
const err = Object.assign(
1552+
new Error(
1553+
'15/second request limit reached - reduce calls per second or upgrade your account at quicknode.com',
1554+
),
1555+
{ code: -32007 },
1556+
)
1557+
expect(shouldRetry(err)).toBe(true)
1558+
})
1559+
15471560
test('WalletConnectSessionSettlementError', () => {
15481561
expect(
15491562
shouldRetry(new WalletConnectSessionSettlementError({} as any)),

src/utils/buildRequest.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,12 @@ export function shouldRetry(error: Error) {
298298
// HTTP 200 with a JSON-RPC body of `{ code: 429 }` instead of an HTTP 429,
299299
// so we need to handle this code in addition to the HTTP status check below.
300300
if (error.code === 429) return true
301+
// Request limit exceeded — QuickNode's own non-standard rate-limit code,
302+
// distinct from the standard `LimitExceededRpcError` (`-32005`). Seen in
303+
// production as `{ code: -32007, message: "N/second request limit
304+
// reached - reduce calls per second or upgrade your account at
305+
// quicknode.com" }`.
306+
if (error.code === -32007) return true
301307
return false
302308
}
303309
if (error instanceof HttpRequestError && error.status) {

0 commit comments

Comments
 (0)