Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
title: Hono
description: "Reports Hono errors to Sentry. (default)"
---

_Import name: `Sentry.honoIntegration`_

This integration is enabled by default. If you'd like to modify your default integrations, read [this](./../#modifying-default-integrations).

The `honoIntegration` automatically captures errors from Hono's `onError` function and sends them to Sentry. By default, the integration won't capture errors that have a 3xx or 4xx HTTP status code.

## Options

You can configure the `honoIntegration` by passing an options object to the function.

### `shouldHandleError`

This option allows you to provide a function that determines whether an error should be captured, giving you full control over which errors are sent to Sentry.

The function receives the error as an argument and should return `true` if the error should be reported, and `false` otherwise.

For example, to report all errors except for 404s, add this to the integrations array when initializing Sentry:

```javascript
integrations: [
honoIntegration({
shouldHandleError(error) {
// return true // Would report all errors

if (error instanceof HTTPException && error.status === 404) {
// Don't report 404s
return false;
}
// Report all other errors
return true;
},
}),
]
```
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
### Integrations

| | **Auto Enabled** | **Errors** | **Tracing** | **Cron** | **Additional Context** |
| ---------------------------------------------------- | :--------------: | :--------: | :---------: | :------: | :--------------------: |
| [`dedupeIntegration`](./dedupe) | ✓ | ✓ | | | |
| [`fetchIntegration`](./fetchIntegration) | ✓ | ✓ | ✓ | | |
| [`functionToStringIntegration`](./functiontostring) | ✓ | | | | |
| [`inboundFiltersIntegration`](./inboundfilters) | ✓ | ✓ | | | |
| [`linkedErrorsIntegration`](./linkederrors) | ✓ | ✓ | | | |
| [`requestDataIntegration`](./requestdata) | ✓ | | | | ✓ |
| [`captureConsoleIntegration`](./captureconsole) | | | | | ✓ |
| [`extraErrorDataIntegration`](./extraerrordata) | | | | | ✓ |
| [`rewriteFramesIntegration`](./rewriteframes) | | ✓ | | | |
| | **Auto Enabled** | **Errors** | **Tracing** | **Cron** | **Additional Context** |
|-----------------------------------------------------|:----------------:|:----------:|:-----------:|:--------:|:----------------------:|
| [`dedupeIntegration`](./dedupe) | ✓ | ✓ | | | |
| [`fetchIntegration`](./fetchIntegration) | ✓ | ✓ | ✓ | | |
| [`functionToStringIntegration`](./functiontostring) | ✓ | | | | |
| [`inboundFiltersIntegration`](./inboundfilters) | ✓ | ✓ | | | |
| [`linkedErrorsIntegration`](./linkederrors) | ✓ | ✓ | | | |
| [`requestDataIntegration`](./requestdata) | ✓ | | | | ✓ |
| [`captureConsoleIntegration`](./captureconsole) | | | | | ✓ |
| [`extraErrorDataIntegration`](./extraerrordata) | | | | | ✓ |
| [`rewriteFramesIntegration`](./rewriteframes) | | ✓ | | | |
| [`honoIntegration`](./hono) | ✓ | ✓ | | | |
Original file line number Diff line number Diff line change
@@ -1,34 +1,5 @@
### Report Unhandled Exceptions

Next, bind an `onError` hook to report unhandled exceptions to Sentry:
Sentry automatically reports exceptions reported by the `onError` function from Hono. In case the error comes with a status code, it captures all errors except for the ones with a 3xx or 4xx status code.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

l: maybe it is worth to mention that this is only true, unless it gets overwritten by shouldHandleError. Or the other way around to write inside shouldHandleError that this will overwrite the auto reports from Sentry

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'll just add a "By default, " at the beginning of the sentence, since I am referring to customizing the behavior below.


```javascript
const app = new Hono()
// Add an onError hook to report unhandled exceptions to Sentry.
.onError((err, c) => {
// Report _all_ unhandled errors.
Sentry.captureException(err);
if (err instanceof HTTPException) {
return err.getResponse();
}
// Or just report errors which are not instances of HTTPException
// Sentry.captureException(err);
return c.json({ error: "Internal server error" }, 500);
})

// Bind global context via Hono middleware
.use((c, next) => {
Sentry.setUser({
email: c.session.user.email,
});

Sentry.setTag("project_id", c.session.projectId);

return next();
})

// Your routes...
.get("/", () => {
// ...
});
```
To learn how to customize this behavior, see the [`honoIntegration` documentation](/platforms/javascript/guides/cloudflare/configuration/integrations/hono/).
Loading