Allow overriding the default 500 response on uncaught errors
Opened this issue · 0 comments
aleclarson commented
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' } }]
}
})