Skip to content

Commit b3f72ac

Browse files
docs(cloudflare): Add docs for honoIntegration (#15251)
## DESCRIBE YOUR PR This adds docs for this PR: getsentry/sentry-javascript#17743 ## IS YOUR CHANGE URGENT? Help us prioritize incoming PRs by letting us know when the change needs to go live. - [ ] Urgent deadline (GA date, etc.): <!-- ENTER DATE HERE --> - [ ] Other deadline: <!-- ENTER DATE HERE --> - [ ] None: Not urgent, can wait up to 1 week+ ## SLA - Teamwork makes the dream work, so please add a reviewer to your PRs. - Please give the docs team up to 1 week to review your PR unless you've added an urgent due date to it. Thanks in advance for your help! ## PRE-MERGE CHECKLIST *Make sure you've checked the following before merging your changes:* - [ ] Checked Vercel preview for correctness, including links - [ ] PR was reviewed and approved by any necessary SMEs (subject matter experts) - [ ] PR was reviewed and approved by a member of the [Sentry docs team](https://github.com/orgs/getsentry/teams/docs) --------- Co-authored-by: Sarah Mischinger <[email protected]>
1 parent 3fc32cb commit b3f72ac

File tree

3 files changed

+53
-42
lines changed

3 files changed

+53
-42
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
title: Hono
3+
description: "Reports Hono errors to Sentry. (default)"
4+
---
5+
6+
_Import name: `Sentry.honoIntegration`_
7+
8+
This integration is enabled by default. If you'd like to modify your default integrations, read [this](./../#modifying-default-integrations).
9+
10+
The `honoIntegration` automatically captures errors from Hono's `onError` function and sends them to Sentry. By default, the integration doesn't capture errors that have a 3xx or 4xx HTTP status code.
11+
12+
## Options
13+
14+
You can configure the `honoIntegration` by passing an options object to the function.
15+
16+
### `shouldHandleError`
17+
18+
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.
19+
20+
The function receives the error as an argument and should return `true` if the error should be reported, and `false` otherwise.
21+
22+
For example, to report all errors except for 404s, add this to the integrations array when initializing Sentry:
23+
24+
```javascript
25+
integrations: [
26+
honoIntegration({
27+
shouldHandleError(error) {
28+
// return true // Would report all errors
29+
30+
if (error instanceof HTTPException && error.status === 404) {
31+
// Don't report 404s
32+
return false;
33+
}
34+
// Report all other errors
35+
return true;
36+
},
37+
}),
38+
]
39+
```
Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
### Integrations
22

3-
| | **Auto Enabled** | **Errors** | **Tracing** | **Cron** | **Additional Context** |
4-
| ---------------------------------------------------- | :--------------: | :--------: | :---------: | :------: | :--------------------: |
5-
| [`dedupeIntegration`](./dedupe) ||| | | |
6-
| [`fetchIntegration`](./fetchIntegration) |||| | |
7-
| [`functionToStringIntegration`](./functiontostring) || | | | |
8-
| [`inboundFiltersIntegration`](./inboundfilters) ||| | | |
9-
| [`linkedErrorsIntegration`](./linkederrors) ||| | | |
10-
| [`requestDataIntegration`](./requestdata) || | | ||
11-
| [`captureConsoleIntegration`](./captureconsole) | | | | ||
12-
| [`extraErrorDataIntegration`](./extraerrordata) | | | | ||
13-
| [`rewriteFramesIntegration`](./rewriteframes) | || | | |
3+
| | **Auto Enabled** | **Errors** | **Tracing** | **Cron** | **Additional Context** |
4+
|-----------------------------------------------------|:----------------:|:----------:|:-----------:|:--------:|:----------------------:|
5+
| [`dedupeIntegration`](./dedupe) ||| | | |
6+
| [`fetchIntegration`](./fetchIntegration) |||| | |
7+
| [`functionToStringIntegration`](./functiontostring) || | | | |
8+
| [`inboundFiltersIntegration`](./inboundfilters) ||| | | |
9+
| [`linkedErrorsIntegration`](./linkederrors) ||| | | |
10+
| [`requestDataIntegration`](./requestdata) || | | ||
11+
| [`captureConsoleIntegration`](./captureconsole) | | | | ||
12+
| [`extraErrorDataIntegration`](./extraerrordata) | | | | ||
13+
| [`rewriteFramesIntegration`](./rewriteframes) | || | | |
14+
| [`honoIntegration`](./hono) ||| | | |
Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,5 @@
11
### Report Unhandled Exceptions
22

3-
Next, bind an `onError` hook to report unhandled exceptions to Sentry:
3+
By default, Sentry 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.
44

5-
```javascript
6-
const app = new Hono()
7-
// Add an onError hook to report unhandled exceptions to Sentry.
8-
.onError((err, c) => {
9-
// Report _all_ unhandled errors.
10-
Sentry.captureException(err);
11-
if (err instanceof HTTPException) {
12-
return err.getResponse();
13-
}
14-
// Or just report errors which are not instances of HTTPException
15-
// Sentry.captureException(err);
16-
return c.json({ error: "Internal server error" }, 500);
17-
})
18-
19-
// Bind global context via Hono middleware
20-
.use((c, next) => {
21-
Sentry.setUser({
22-
email: c.session.user.email,
23-
});
24-
25-
Sentry.setTag("project_id", c.session.projectId);
26-
27-
return next();
28-
})
29-
30-
// Your routes...
31-
.get("/", () => {
32-
// ...
33-
});
34-
```
5+
To learn how to customize this behavior, see the [`honoIntegration` documentation](/platforms/javascript/guides/cloudflare/configuration/integrations/hono/).

0 commit comments

Comments
 (0)