Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deps: update statuses to v2.0.1 #1480

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,10 @@ const proto = module.exports = {
if ('ENOENT' === err.code) statusCode = 404;

// default to 500
if ('number' !== typeof statusCode || !statuses[statusCode]) statusCode = 500;
if ('number' !== typeof statusCode || !statuses.message[statusCode]) statusCode = 500;

// respond
const code = statuses[statusCode];
const code = statuses.message[statusCode];
const msg = err.expose ? err.message : code;
this.status = err.status = statusCode;
this.length = Buffer.byteLength(msg);
Expand Down
4 changes: 2 additions & 2 deletions lib/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ module.exports = {
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];
if (this.req.httpVersionMajor < 2) this.res.statusMessage = statuses.message[code];
if (this.body && statuses.empty[code]) this.body = null;
},

Expand All @@ -99,7 +99,7 @@ module.exports = {
*/

get message() {
return this.res.statusMessage || statuses[this.status];
return this.res.statusMessage || statuses.message[this.status];
},

/**
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"on-finished": "^2.3.0",
"only": "~0.0.2",
"parseurl": "^1.3.2",
"statuses": "^1.5.0",
"statuses": "^2.0.0",
"type-is": "^1.6.16",
"vary": "^1.1.2"
},
Expand Down
2 changes: 1 addition & 1 deletion test/application/respond.js
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ describe('app.respond', () => {
describe('with custom status=700', () => {
it('should respond with the associated status message', async() => {
const app = new Koa();
statuses['700'] = 'custom status';
Copy link
Member

Choose a reason for hiding this comment

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

this is a breaking change for users who want to customize status code

Copy link
Member

Choose a reason for hiding this comment

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

IMO we need to provide a more controllable way to customize status code.

Copy link
Member Author

Choose a reason for hiding this comment

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

this is a breaking change for users who want to customize status code

According to what I understand form you, we should leave this PR to Koa@3 !!

Copy link
Member Author

Choose a reason for hiding this comment

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

IMO we need to provide a more controllable way to customize status code.

Perhaps we can provide a method to store, set, cache.. custom messages for custom codes.

I think this approach is simple and clean.

statuses.message['700'] = 'custom status';

app.use(ctx => {
ctx.status = 700;
Expand Down
2 changes: 1 addition & 1 deletion test/response/status.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('res.status=', () => {
});

describe('and custom status', () => {
beforeEach(() => statuses['700'] = 'custom status');
beforeEach(() => statuses.message['700'] = 'custom status');

it('should set the status', () => {
const res = response();
Expand Down