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

About Customize HTTP Status Codes #350

Closed
zedgu opened this issue Sep 27, 2014 · 7 comments
Closed

About Customize HTTP Status Codes #350

zedgu opened this issue Sep 27, 2014 · 7 comments

Comments

@zedgu
Copy link

zedgu commented Sep 27, 2014

We have to use the customize HTTP codes for some reasons like login expired(code 440 , see http:https://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?

@jonathanong
Copy link
Member

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

@jonathanong
Copy link
Member

@zedgu can you tell me if changing the statuses module globally works for you?

@zedgu
Copy link
Author

zedgu commented Sep 29, 2014

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?

@dead-horse
Copy link
Member

change this line to https://github.com/jshttp/http-errors/blob/master/index.js#L31

you can make a PR

@zedgu
Copy link
Author

zedgu commented Sep 29, 2014

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

@dead-horse
Copy link
Member

yep, you should change them both. :)

@jonathanong
Copy link
Member

oh yeah. both should be less strict. PR welcomed :)

dead-horse added a commit to dead-horse/koa that referenced this issue Oct 1, 2014
@zedgu zedgu closed this as completed Oct 2, 2014
dead-horse added a commit to dead-horse/koa that referenced this issue Oct 9, 2014
dead-horse added a commit to dead-horse/koa that referenced this issue Oct 9, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants