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
3 changes: 3 additions & 0 deletions lib/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
throw new TypeError('Invalid status code: ' + statusCode);
throw new TypeError(`statusCode must be a valid number to res.sendStatus`);

I think it seems consistent

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree

}
var body = statuses.message[statusCode] || String(statusCode)

this.status(statusCode);
Expand Down
12 changes: 12 additions & 0 deletions test/res.sendStatus.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
})
})
Loading