feat: change set status assert, allowing valid custom statuses (#1308)
This commit is contained in:
parent
72f325b78e
commit
b7bfa7113b
2 changed files with 4 additions and 4 deletions
|
@ -83,8 +83,8 @@ module.exports = {
|
||||||
set status(code) {
|
set status(code) {
|
||||||
if (this.headerSent) return;
|
if (this.headerSent) return;
|
||||||
|
|
||||||
assert('number' == typeof code, 'status code must be a number');
|
assert(Number.isInteger(code), 'status code must be a number');
|
||||||
assert(statuses[code], `invalid status code: ${code}`);
|
assert(code >= 100 && code <= 999, `invalid status code: ${code}`);
|
||||||
this._explicitStatus = true;
|
this._explicitStatus = true;
|
||||||
this.res.statusCode = code;
|
this.res.statusCode = code;
|
||||||
if (this.req.httpVersionMajor < 2) this.res.statusMessage = statuses[code];
|
if (this.req.httpVersionMajor < 2) this.res.statusMessage = statuses[code];
|
||||||
|
|
|
@ -24,8 +24,8 @@ describe('res.status=', () => {
|
||||||
describe('and invalid', () => {
|
describe('and invalid', () => {
|
||||||
it('should throw', () => {
|
it('should throw', () => {
|
||||||
assert.throws(() => {
|
assert.throws(() => {
|
||||||
response().status = 999;
|
response().status = 99;
|
||||||
}, /invalid status code: 999/);
|
}, /invalid status code: 99/);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue