From 963b1ac0de4083b8d0fc7c8d2f9f0202e9d15bfd Mon Sep 17 00:00:00 2001 From: Markkus Millend Date: Thu, 1 Jun 2023 23:31:51 +0200 Subject: [PATCH] Sentry middleware: fix undefined DSN environment variable error (#89) * Use optional chaining for determining Sentry DSN from environment * Bump Hono version for Sentry middleware * Fix tests on Deno * Add changeset for Sentry middleware patch * Denoify the new Sentry patch --- .changeset/kind-parents-play.md | 5 +++++ packages/sentry/deno_dist/index.ts | 2 +- packages/sentry/deno_test/deps.ts | 2 +- packages/sentry/package.json | 4 ++-- packages/sentry/src/index.ts | 2 +- 5 files changed, 10 insertions(+), 5 deletions(-) create mode 100644 .changeset/kind-parents-play.md diff --git a/.changeset/kind-parents-play.md b/.changeset/kind-parents-play.md new file mode 100644 index 00000000..2945a538 --- /dev/null +++ b/.changeset/kind-parents-play.md @@ -0,0 +1,5 @@ +--- +'@hono/sentry': patch +--- + +Use optional chaining for determining Sentry DSN from environment (#89) diff --git a/packages/sentry/deno_dist/index.ts b/packages/sentry/deno_dist/index.ts index 75f82148..a3d740f0 100644 --- a/packages/sentry/deno_dist/index.ts +++ b/packages/sentry/deno_dist/index.ts @@ -41,7 +41,7 @@ export const sentry = ( hasExecutionContext = false } const sentry = new Toucan({ - dsn: c.env.SENTRY_DSN ?? c.env.NEXT_PUBLIC_SENTRY_DSN, + dsn: c.env?.SENTRY_DSN ?? c.env?.NEXT_PUBLIC_SENTRY_DSN, allowedHeaders: ['user-agent'], allowedSearchParams: /(.*)/, request: c.req.raw, diff --git a/packages/sentry/deno_test/deps.ts b/packages/sentry/deno_test/deps.ts index 12c276dd..1c02a418 100644 --- a/packages/sentry/deno_test/deps.ts +++ b/packages/sentry/deno_test/deps.ts @@ -1,2 +1,2 @@ export { assert, assertEquals } from 'https://deno.land/std@0.148.0/testing/asserts.ts' -export { Hono } from 'https://deno.land/x/hono@v2.6.1/mod.ts' +export { Hono } from 'https://deno.land/x/hono@v3.2.3/mod.ts' diff --git a/packages/sentry/package.json b/packages/sentry/package.json index 6e03ec52..8f713830 100644 --- a/packages/sentry/package.json +++ b/packages/sentry/package.json @@ -33,7 +33,7 @@ "access": "public" }, "peerDependencies": { - "hono": "^3.0.2" + "hono": "^3.2.3" }, "dependencies": { "toucan-js": "^2.6.1" @@ -61,4 +61,4 @@ "ts-jest": "^28.0.5", "typescript": "^4.7.4" } -} \ No newline at end of file +} diff --git a/packages/sentry/src/index.ts b/packages/sentry/src/index.ts index 2ede2807..82396b08 100644 --- a/packages/sentry/src/index.ts +++ b/packages/sentry/src/index.ts @@ -41,7 +41,7 @@ export const sentry = ( hasExecutionContext = false } const sentry = new Toucan({ - dsn: c.env.SENTRY_DSN ?? c.env.NEXT_PUBLIC_SENTRY_DSN, + dsn: c.env?.SENTRY_DSN ?? c.env?.NEXT_PUBLIC_SENTRY_DSN, allowedHeaders: ['user-agent'], allowedSearchParams: /(.*)/, request: c.req.raw,