diff --git a/lib/response.js b/lib/response.js index c01526e1c..f9b33d5e8 100644 --- a/lib/response.js +++ b/lib/response.js @@ -83,8 +83,8 @@ module.exports = { set status(code) { if (this.headerSent) return; - assert('number' == typeof code, 'status code must be a number'); - assert(statuses[code], `invalid status code: ${code}`); + assert(Number.isInteger(code), 'status code must be a number'); + assert(code >= 100 && code <= 999, `invalid status code: ${code}`); this._explicitStatus = true; this.res.statusCode = code; if (this.req.httpVersionMajor < 2) this.res.statusMessage = statuses[code]; diff --git a/test/response/status.js b/test/response/status.js index 63e2ff687..af3394885 100644 --- a/test/response/status.js +++ b/test/response/status.js @@ -24,8 +24,8 @@ describe('res.status=', () => { describe('and invalid', () => { it('should throw', () => { assert.throws(() => { - response().status = 999; - }, /invalid status code: 999/); + response().status = 99; + }, /invalid status code: 99/); }); });