Skip to content

Commit b7bfa71

Browse files
fl0wdead-horse
authored andcommitted
feat: change set status assert, allowing valid custom statuses (#1308)
1 parent 72f325b commit b7bfa71

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

lib/response.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ module.exports = {
8383
set status(code) {
8484
if (this.headerSent) return;
8585

86-
assert('number' == typeof code, 'status code must be a number');
87-
assert(statuses[code], `invalid status code: ${code}`);
86+
assert(Number.isInteger(code), 'status code must be a number');
87+
assert(code >= 100 && code <= 999, `invalid status code: ${code}`);
8888
this._explicitStatus = true;
8989
this.res.statusCode = code;
9090
if (this.req.httpVersionMajor < 2) this.res.statusMessage = statuses[code];

test/response/status.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ describe('res.status=', () => {
2424
describe('and invalid', () => {
2525
it('should throw', () => {
2626
assert.throws(() => {
27-
response().status = 999;
28-
}, /invalid status code: 999/);
27+
response().status = 99;
28+
}, /invalid status code: 99/);
2929
});
3030
});
3131

0 commit comments

Comments
 (0)