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

Make a complete example of onError handling in the docs #2603

Open
Soviut opened this issue May 4, 2024 · 2 comments
Open

Make a complete example of onError handling in the docs #2603

Soviut opened this issue May 4, 2024 · 2 comments
Labels
enhancement New feature or request.

Comments

@Soviut
Copy link

Soviut commented May 4, 2024

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.

@Soviut Soviut added the enhancement New feature or request. label May 4, 2024
@fzn0x
Copy link
Contributor

fzn0x commented May 6, 2024

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

@Soviut
Copy link
Author

Soviut commented May 6, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request.
Projects
None yet
Development

No branches or pull requests

2 participants