Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ module.exports = res
*/

res.status = function status(code) {
// Prevent BigInt serialization error
if (typeof code !== 'number') {
throw new TypeError(`Invalid status code: ${code} (${typeof code}). Status code must be a number.`);
}
// 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.`);
Expand Down
12 changes: 12 additions & 0 deletions test/res.status.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
});
});
});
Expand Down