alloc / saus

Vite SSR/SSG framework that aspires to be a layer for opinionated web frameworks to build upon
Other
38 stars 1 forks source link

Allow overriding the default 500 response on uncaught errors #66

Open aleclarson opened 2 years ago

aleclarson commented 2 years ago

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' } }]
  }
})