About Customize HTTP Status Codes
Closed this issue · 7 comments
We have to use the customize HTTP codes for some reasons like login expired
(code 440 , see http://en.wikipedia.org/wiki/List_of_HTTP_status_codes) or customize code range 7xx.
But they'll throw Error by both API this.status
and this.throw
, because there're only RFC codes in http.STATUS_CODES and jshttp/statuses/codes.json.
Should we let koa to support the customize HTTP status codes?
i made it easier to add custom status codes in statuses
. feel free to add them :D
for custom status codes, it might actually be easier to add the status codes globally to the statuses
module at start up.
var statuses = require('statuses');
statuses['700'] = 'custom status';
lol
@zedgu can you tell me if changing the statuses module globally works for you?
Actually, we need status codes for http response header, not a simple message for node server side console.
And, we only got 500
in browser and Internal Server Error
on server side.
var koa = require('koa')
, app = koa()
, statuses = require('statuses')
;
statuses['440'] = 'login expired';
app.use(function *(next) {
this.throw(440);
yield next;
});
app.listen(3000);
anything wrong?
Should we just don't check http.STATUS_CODES in here https://github.com/koajs/koa/blob/master/lib/context.js#L129 ,
or
only check 100 < err.status < 600
?
change this line to https://github.com/jshttp/http-errors/blob/master/index.js#L31
you can make a PR
my fault, this line https://github.com/koajs/koa/blob/master/lib/response.js#L72 is the problem
and i'd love to make the PR
yep, you should change them both. :)
oh yeah. both should be less strict. PR welcomed :)