Skip to content

fix: preserve BigInt values when formatting HTTP errors - #851

Merged
wolfy1339 merged 2 commits into
octokit:mainfrom
pradeep-ramola:fix/bigint-error-messages
Nov 29, 2026
Merged

wolfy1339 merged 2 commits into
octokit:mainfrom
pradeep-ramola:fix/bigint-error-messages

Conversation

@pradeep-ramola

Copy link
Copy Markdown
Contributor

Resolves #850


Before the change?

JSONParse preserves large JSON integers as BigInt, but toErrorMessage uses built-in JSON.stringify for error details and fallback bodies. A valid HTTP error containing such an integer therefore throws TypeError: Do not know how to serialize a BigInt before RequestError can be constructed, losing the status/request/response context.

After the change?

Reuse the already-imported JSONStringify at both formatting sites. HTTP errors retain their status, their parsed response (including exact BigInt values), and a readable message. No new dependency or public API change is needed.

Added six regressions for nested error details, primitive error details, and object/array/positive-integer/negative-integer fallback bodies. Each checks the RequestError instance, status, message, request metadata, and parsed response. All six fail on unmodified main and pass with the fix.

Validation on Windows:

  • Full coverage-enabled suite on Node.js 22.23.5 and 24.16.0: 106 passed, 2 existing skips, with 100% statements, branches, functions, and lines.
  • npm run build: passed.
  • Strict Prettier check of both changed files: passed.
  • Repository-wide npm run lint -- --end-of-line auto: passed. Plain npm test stops in its lint pre-step because this Windows checkout uses CRLF in unchanged files; the full suite above was run directly using node node_modules/vitest/vitest.mjs run --coverage. No formatter configuration or unrelated files were changed.
  • 36 additional checks against the compiled public export, spanning the six payloads, HTTP 400/422/500, and JSON/SCIM JSON content types. These checks and the new regressions use injected fetch responses, with no network requests.

Pull request checklist

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been reviewed and added / updated if needed (for bug fixes / features)

No documentation update is needed: this restores the existing HTTP error contract rather than adding behavior users must configure.

Does this introduce a breaking change?

  • Yes
  • No

@octokit

octokit Bot commented Nov 29, 2026

Copy link
Copy Markdown

👋 Hi! Thank you for this contribution! Just to let you know, our GitHub SDK team does a round of issue and PR reviews twice a week, every Monday and Friday! We have a process in place for prioritizing and responding to your input. Because you are a part of this community please feel free to comment, add to, or pick up any issues/PRs that are labeled with Status: Up for grabs. You & others like you are the reason all of this works! So thank you & happy coding! 🚀

@wolfy1339
wolfy1339 merged commit a6f394d into octokit:main Nov 29, 2026
7 checks passed
@github-project-automation github-project-automation Bot moved this from 🆕 Triage to ✅ Done in 🧰 Octokit Active Nov 29, 2026
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 10.0.18 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

[BUG]: BigInt error bodies throw TypeError instead of RequestError

2 participants