Deno library + re-throw error

pull/31/head
Samuel Lippert 2022-08-10 14:54:58 -05:00
parent 9294150029
commit b47e0004e2
No known key found for this signature in database
GPG Key ID: 3762857AF8948B2C
3 changed files with 27 additions and 13 deletions

View File

@ -17,6 +17,21 @@ app.get('/', (c) => c.text('foo'))
export default app
```
## Deno
```ts
import { serve } from 'https://deno.land/std/http/server.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('*', sentry())
app.get('/', (c) => c.text('foo'))
serve(app.fetch)
```
## Author
Yusuke Wada <https://github.com/yusukebe>

View File

@ -1,19 +1,17 @@
import type { Handler } from 'https://raw.githubusercontent.com/honojs/hono/v2.0.6/deno_dist/mod.ts'
// import Toucan from '../node_modules/toucan-js/dist/index.d.ts'
import * as Sentry from 'https://deno.land/x/sentry_deno/main.ts'
export const sentry = (): Handler => {
return async (c, next) => {
// const sentry = new Toucan({
// dsn: c.env.SENTRY_DSN || || c.env.NEXT_PUBLIC_SENTRY_DSN,
// request: c.req,
// allowedHeaders: ['user-agent'],
// allowedSearchParams: /(.*)/,
// })
// try {
await next()
// } catch (error) {
// sentry.captureException(error)
// }
Sentry.init({
dsn: c.env.SENTRY_DSN || c.env.NEXT_PUBLIC_SENTRY_DSN,
tracesSampleRate: 1.0,
})
try {
await next()
} catch (error) {
Sentry.captureException(error)
throw error
}
}
}

View File

@ -14,6 +14,7 @@ export const sentry = (): Handler => {
await next()
} catch (error) {
sentry.captureException(error)
throw error
}
}
}