koajs / json-error

Error handler for pure-JSON apps
MIT License
91 stars 3 forks source link

Extend no throw error handling #44

Closed Sytten closed 5 years ago

Sytten commented 5 years ago

Some middlewares I use won't don't throw when something is wrong, but will return a 500. Currently you handle only 404: https://github.com/koajs/json-error/blob/9d5fe96551e6901206eb92adfec232ea19aa5375/lib/middleware.js#L52 It would nice to handle all error status (maybe make is configurable by the user). It's not that complicated, I don't have time!

nfantone commented 5 years ago

Hi @Sytten!

The throwing of 404 errors is there to avoid showing an empty response to the client in case your error status is 404 and there's no explicit body; or if no status is provided.

The error handling is actually application specific. This library focuses on formatting errors and how those are presented to users. If you want to throw a 500 (or any other status), just do so when appropriate using ctx.throw in your own middlewares. Those will be intercepted by json-error and formatted appropriately.

Let me know if I can help you further with your case.

Sytten commented 5 years ago

Make sense, I guess I will wrap my external lib with another middleware.