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

why context.onerror remove headers? #613

Closed
menems opened this issue Dec 2, 2015 · 1 comment
Closed

why context.onerror remove headers? #613

menems opened this issue Dec 2, 2015 · 1 comment

Comments

@menems
Copy link
Contributor

menems commented Dec 2, 2015

https://github.com/koajs/koa/blob/v2.x/lib/context.js#L121

I don't understand why headers are removed if you throw an error?
I'm sure there is a reason.

concrete example: if I use cors and jwt middleware. domain is authorize to make a request but try to access a unauthorize api, why Access-control...headers should be removed?

The only way is for now, to catch the error(401) and set ctx.status = 401.

But if i want to centralize my errors, i 'd like to use the app.on('error') for example and not add before all other middeleware something like that:

app.use(ctx => {
   return next().catch(e => ctx.status = e.status)
}

@tj
Copy link
Member

tj commented Dec 2, 2015

dup, convo is over at #571, not really a consensus yet but it's definitely awkward

@tj tj closed this as completed Dec 2, 2015
@tj tj added the duplicate label Dec 2, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants