Skip to content

fix: avoid JSON serialization error in res.status for BigInt values - #7489

Closed
dajiaohuang wants to merge 1 commit into
expressjs:masterfrom
dajiaohuang:fix/6756-bigint-status
Closed

dajiaohuang wants to merge 1 commit into
expressjs:masterfrom
dajiaohuang:fix/6756-bigint-status

Conversation

@dajiaohuang

Copy link
Copy Markdown

When res.status() or res.sendStatus() received a BigInt (or other values that JSON.stringify cannot serialize), the error message construction would throw:

TypeError: Do not know how to serialize a BigInt
    at JSON.stringify (<anonymous>)

This obscured the actual intended error message about invalid status code. The fix replaces JSON.stringify() with String() in error messages to safely convert any value to a string representation.

Before:

res.sendStatus(200n)
// throws: TypeError: Do not know how to serialize a BigInt

After:

res.sendStatus(200n)
// throws: TypeError: Invalid status code: 200. Status code must be an integer.

Fixes #6756

…r values

When res.status() or res.sendStatus() received a BigInt (or other
values that JSON.stringify cannot serialize), the error message
construction would throw:
  TypeError: Do not know how to serialize a BigInt

This obscured the actual intended error message about invalid status
code. The fix replaces JSON.stringify() with String() in error messages
to safely convert any value to a string representation.

Before:
  res.sendStatus(200n)
  // throws: TypeError: Do not know how to serialize a BigInt

After:
  res.sendStatus(200n)
  // throws: TypeError: Invalid status code: 200. Status code must be an integer.

Fixes expressjs#6756
@krzysdz

krzysdz commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

Duplicate of #6848 with the same problems

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TypeError: Do not know how to serialize a BigInt when using sendStatus with a BigNum instead of intended error message

2 participants