Skip to content

fix: retry http JSON-RPC errors from non-2xx responses by status - #5286

Merged
jxom merged 5 commits into
mainfrom
jxom/http-rpc-error-retry
Oct 24, 2026
Merged

jxom merged 5 commits into
mainfrom
jxom/http-rpc-error-retry

Conversation

@jxom

@jxom jxom commented Oct 24, 2026

Copy link
Copy Markdown
Member

Non-2xx http responses with a JSON-RPC error body now throw RpcRequestError carrying status and headers. Retries then follow the HTTP status and Retry-After, while the RPC error class and revert data are kept.

Related: #5282

@vercel

vercel Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
viem Ready Ready Preview Oct 24, 2026 9:09am UTC

Request Review

@changeset-bot

changeset-bot Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: ba85417

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
viem Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-24T09:06:25.588077Z ba85417 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@jxom
jxom enabled auto-merge (squash) October 24, 2026 03:33
@jxom
jxom disabled auto-merge October 24, 2026 03:33
@pkg-pr-new

pkg-pr-new Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/viem@5286

commit: ba85417

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 58741d0081

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/utils/rpc/http.ts Resolved
Comment thread src/utils/buildRequest.ts Outdated
Comment on lines +272 to +275
const retryAfter =
getHttpError(error)?.headers?.get('Retry-After')
if (retryAfter?.match(/\d/))
return Number.parseInt(retryAfter, 10) * 1000

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Parse HTTP-date Retry-After values before retrying

When a non-2xx JSON-RPC response supplies the valid HTTP-date form of Retry-After (for example, Sat, 24 Oct 2026 04:00:00 GMT), /\d/ accepts the header but Number.parseInt returns NaN; withRetry then treats that delay as falsy and retries immediately. This can turn a provider's explicit backoff request into a rapid retry burst, so parse both delay-seconds and HTTP-date forms and calculate the remaining delay.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not changed in this PR: HttpRequestError already uses the same Retry-After parsing, so HTTP-date support is left for a separate fix.

🤖 Addressed by Claude Code

Comment thread src/errors/request.ts Resolved
Comment thread src/clients/transports/http.test.ts Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0053e28bf0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/clients/transports/http.test.ts Resolved
…etry

# Conflicts:
#	src/utils/buildRequest.ts
#	src/utils/rpc/http.ts
@jxom
jxom merged commit 8e058ca into main Oct 24, 2026
38 of 40 checks passed
@jxom
jxom deleted the jxom/http-rpc-error-retry branch October 24, 2026 09:11
@github-actions github-actions Bot mentioned this pull request Oct 24, 2026

This branch was successfully deployed

1 active deployment
Preview — ba854174 Deployed Oct 24, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant