diff --git a/README.md b/README.md index d2a7372c..27d4f37d 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,17 @@ -# Hello middleware for Hono +# Sentry middleware for Hono -An example project of the third-party middleware for [Hono](https://github.com/honojs/hono). -This middleware add `X-Message` header to the Response. +Sentry middleware for [Hono](https://github.com/honojs/hono). +This middleware sends captured exceptions to the Sentry data source named by the `SENTRY_DSN` environment variable via [toucan-js](https://github.com/robertcepa/toucan-js). ## Usage ```ts -import { hello } from '@honojs/hello' +import { sentry } from '@honojs/sentry' import { Hono } from 'hono' const app = new Hono() -app.use('*', hello('Hello!! Hono!!')) +app.use('*', sentry()) app.get('/', (c) => c.text('foo')) export default app @@ -21,12 +21,12 @@ export default app ```ts import { serve } from 'https://deno.land/std/http/server.ts' -import { hello } from 'https://deno.land/x/hono_hello/mod.ts' +import { sentry } from 'https://deno.land/x/hono_sentry/mod.ts' import { Hono } from 'https://deno.land/x/hono/mod.ts' const app = new Hono() -app.use('*', hello('Hello!! Hono!!')) +app.use('*', sentry()) app.get('/', (c) => c.text('foo')) serve(app.fetch) diff --git a/deno_dist/README.md b/deno_dist/README.md index d2a7372c..27d4f37d 100644 --- a/deno_dist/README.md +++ b/deno_dist/README.md @@ -1,17 +1,17 @@ -# Hello middleware for Hono +# Sentry middleware for Hono -An example project of the third-party middleware for [Hono](https://github.com/honojs/hono). -This middleware add `X-Message` header to the Response. +Sentry middleware for [Hono](https://github.com/honojs/hono). +This middleware sends captured exceptions to the Sentry data source named by the `SENTRY_DSN` environment variable via [toucan-js](https://github.com/robertcepa/toucan-js). ## Usage ```ts -import { hello } from '@honojs/hello' +import { sentry } from '@honojs/sentry' import { Hono } from 'hono' const app = new Hono() -app.use('*', hello('Hello!! Hono!!')) +app.use('*', sentry()) app.get('/', (c) => c.text('foo')) export default app @@ -21,12 +21,12 @@ export default app ```ts import { serve } from 'https://deno.land/std/http/server.ts' -import { hello } from 'https://deno.land/x/hono_hello/mod.ts' +import { sentry } from 'https://deno.land/x/hono_sentry/mod.ts' import { Hono } from 'https://deno.land/x/hono/mod.ts' const app = new Hono() -app.use('*', hello('Hello!! Hono!!')) +app.use('*', sentry()) app.get('/', (c) => c.text('foo')) serve(app.fetch) diff --git a/deno_dist/index.ts b/deno_dist/index.ts index e6f18bf8..1e620330 100644 --- a/deno_dist/index.ts +++ b/deno_dist/index.ts @@ -1,8 +1,19 @@ import type { Handler } from 'https://raw.githubusercontent.com/honojs/hono/v2.0.6/deno_dist/mod.ts' +import Toucan from 'toucan-js' -export const hello = (message: string = 'Hello'): Handler => { +export const hello = (): Handler => { return async (c, next) => { - await next() - c.res.headers.append('X-Message', message) + const sentry = new Toucan({ + dsn: c.env.SENTRY_DSN, + request: c.req, + allowedHeaders: ['user-agent'], + allowedSearchParams: /(.*)/, + }) + + try { + await next() + } catch (error) { + sentry.captureException(error) + } } }