Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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

}
Copy link
Member

@wesleytodd wesleytodd Dec 12, 2025

Choose a reason for hiding this comment

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

Agreed with @jonchurch, move this to res.status, but throwing for BigInt is the right way to go.

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)
})
Copy link
Member

Choose a reason for hiding this comment

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

This test will need to move to res.status.js after the other change.

})
})
Loading