express icon indicating copy to clipboard operation
express copied to clipboard

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

Open joshua-rogers-exodus opened this issue 4 months ago • 12 comments

I know this is a stupid scenario, but I thought I'd report this bug because it probably is expected that it'll be caught:

// server.js
const express = require('express');
const app = express();

// Catch everything and return 200n
app.use((_req, res) => res.sendStatus(200n));

const port = process.env.PORT || 3000;
app.listen(port, () => console.log(`OK server on :${port}`));
$ node index.js & curl localhost:3000 &>/dev/null
[2] 4419
TypeError: Do not know how to serialize a BigInt
    at JSON.stringify (<anonymous>)
    at ServerResponse.status (/private/tmp/lol/node_modules/express/lib/response.js:65:54)
    at ServerResponse.sendStatus (/private/tmp/lol/node_modules/express/lib/response.js:329:8)
    at /private/tmp/lol/index.js:5:28
    at Layer.handleRequest (/private/tmp/lol/node_modules/router/lib/layer.js:152:17)
    at trimPrefix (/private/tmp/lol/node_modules/router/index.js:342:13)
    at /private/tmp/lol/node_modules/router/index.js:297:9
    at processParams (/private/tmp/lol/node_modules/router/index.js:582:12)
    at next (/private/tmp/lol/node_modules/router/index.js:291:5)
    at Function.handle (/private/tmp/lol/node_modules/router/index.js:186:3

joshua-rogers-exodus avatar Sep 13 '25 01:09 joshua-rogers-exodus