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

Allow overriding the default 500 response on uncaught errors #66

Open
aleclarson opened this issue Jun 1, 2022 · 0 comments
Open

Allow overriding the default 500 response on uncaught errors #66

aleclarson opened this issue Jun 1, 2022 · 0 comments
Labels
http Related to HTTP request/response features proposal An idea not set in stone

Comments

@aleclarson
Copy link
Contributor

aleclarson commented Jun 1, 2022

Proposal: Add a runtime hook (something like interpretErrors) that adds a handler that runs when an endpoint throws an error. The handler can return a ResponseTuple array or undefined (call next handler or send a 500 response).

interpretErrors((error, req) => {
  if (req.method == 'post' && error.message == 'Unexpected end of JSON input') {
    return [400, null, { json: { error: 'malformed-json' } }]
  }
})
@aleclarson aleclarson added proposal An idea not set in stone http Related to HTTP request/response features labels Jun 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
http Related to HTTP request/response features proposal An idea not set in stone
Projects
None yet
Development

No branches or pull requests

1 participant