honojs/hono

Make a complete example of onError handling in the docs

Opened this issue · 2 comments

What is the feature you are proposing?

The docs for the app.onError handling have an incomplete example. https://hono.dev/api/exception#handling-httpexception

app.onError((err, c) => {
  if (err instanceof HTTPException) {
    // Get the custom response
    return err.getResponse()
  }
  //...
})

It would be helpful if the example was expanded where the // ... is to show how to pass through the err if it is not an HTTPException.

fzn0x commented

The section itself was described only to handle httpexception, if it is not an HTTPException, you can check here:

https://hono.dev/api/hono#error-handling

The problem is I want to always use HTTPException because it triggers app.onError() which I use for logging to Sentry. Setting the status code does not do this.