diff --git a/docs/platforms/javascript/guides/cloudflare/configuration/integrations/hono.mdx b/docs/platforms/javascript/guides/cloudflare/configuration/integrations/hono.mdx new file mode 100644 index 00000000000000..8ee65b19b363bc --- /dev/null +++ b/docs/platforms/javascript/guides/cloudflare/configuration/integrations/hono.mdx @@ -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; + }, + }), +] +``` diff --git a/platform-includes/configuration/integrations/javascript.cloudflare.mdx b/platform-includes/configuration/integrations/javascript.cloudflare.mdx index 5b4ac52154035a..153ccf4060eed0 100644 --- a/platform-includes/configuration/integrations/javascript.cloudflare.mdx +++ b/platform-includes/configuration/integrations/javascript.cloudflare.mdx @@ -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) | ✓ | ✓ | | | | diff --git a/platform-includes/getting-started-capture-errors/javascript.hono.mdx b/platform-includes/getting-started-capture-errors/javascript.hono.mdx index 9b407be0c6c0b7..d7674a29a4a3c9 100644 --- a/platform-includes/getting-started-capture-errors/javascript.hono.mdx +++ b/platform-includes/getting-started-capture-errors/javascript.hono.mdx @@ -1,34 +1,5 @@ ### Report Unhandled Exceptions -Next, bind an `onError` hook to report unhandled exceptions to Sentry: +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. -```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/).