diff --git a/lib/response.js b/lib/response.js index 7a2f0ecce56..ca2437fb8c4 100644 --- a/lib/response.js +++ b/lib/response.js @@ -64,7 +64,7 @@ module.exports = res res.status = function status(code) { // Check if the status code is not an integer if (!Number.isInteger(code)) { - throw new TypeError(`Invalid status code: ${JSON.stringify(code)}. Status code must be an integer.`); + throw new TypeError(`Invalid status code: ${typeof code === "bigint" ? code : JSON.stringify(code)}. Status code must be an integer.`); } // Check if the status code is outside of Node's valid range if (code < 100 || code > 999) { diff --git a/test/res.status.js b/test/res.status.js index 59c8a57e702..181f2df976a 100644 --- a/test/res.status.js +++ b/test/res.status.js @@ -200,6 +200,18 @@ describe('res', function () { .get('/') .expect(500, /Invalid status code/, done); }); + + it('should raise error for BigInt status code', function (done) { + var app = express() + + app.use(function (req, res) { + res.status(200n).end() + }) + + request(app) + .get('/') + .expect(500, /Invalid status code/, done) + }) }); }); });