evert0n / koa-cors

CORS middleware for Koa
MIT License
243 stars 48 forks source link

handling errors #17

Closed nickpoorman closed 3 months ago

nickpoorman commented 10 years ago

If an error is thrown by someone in the app, ie. this.throw(400) the headers are reset here: https://github.com/koajs/koa/blob/master/lib/context.js#L118 and the cors header is lost.

Seems like this: https://github.com/evert0n/koa-cors/blob/master/index.js#L94 needs to be wrapped in a try catch and have the headers placed back in.

JoshZA commented 8 years ago

I added this package to solve the issue

https://github.com/lusever/koa-cors-error

It would be nice if this was mentioned in this package's documentation

skuester commented 8 years ago

Thanks @JoshZA ! I was also having this problem. It seems to be this behavior should be part of the main koa-cors package, considering its not uncommon for an api server to desire throwing 403's or 400's as guard clauses to an api endpoint.

alexfedin commented 8 years ago

+1

Eli-Goldberg commented 6 years ago

Hi, Is this still an issue?