diff --git a/lib/response.js b/lib/response.js index 7a2f0ecce56..873cd7af178 100644 --- a/lib/response.js +++ b/lib/response.js @@ -326,6 +326,9 @@ res.jsonp = function jsonp(obj) { */ res.sendStatus = function sendStatus(statusCode) { + if (typeof statusCode !== 'number') { + throw new TypeError('Invalid status code: ' + statusCode); + } var body = statuses.message[statusCode] || String(statusCode) this.status(statusCode); diff --git a/test/res.sendStatus.js b/test/res.sendStatus.js index b244cf9d173..10ee0c77c80 100644 --- a/test/res.sendStatus.js +++ b/test/res.sendStatus.js @@ -40,5 +40,17 @@ describe('res', function () { .get('/') .expect(500, /TypeError: Invalid status code/, done) }) + + it('should raise error for BigInt status code', function (done) { + var app = express() + + app.use(function (req, res) { + res.sendStatus(200n) + }) + + request(app) + .get('/') + .expect(500, /TypeError.*Invalid status code/, done) + }) }) })