Skip to content

Commit 29bf0d2

Browse files
authored
fix(sveltekit): Avoid capturing redirect() calls as errors in Cloudflare (#16853)
We want to avoid capturing errors too early and too generally via the `initCloudflareSentryHandle` request handler. Internally, this handler uses a wrapper from `@sentry/cloudflare` to capture errors but prior to #16852 it captured everything that was thrown. This included thrown `redirect()` objects from SvelteKit which serve as control flow mechanisms but should not be captured as errors. This patch opts out of capturing errors in the Cloudflare wrapper. Instead, we rely on our already existing error capturing mechanisms in SvelteKit, which already ignore `redirect()` and a few other error classes.
1 parent b8e7422 commit 29bf0d2

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

packages/sveltekit/src/worker/cloudflare.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ export function initCloudflareSentryHandle(options: CloudflareOptions): Handle {
3737
request: event.request as Request<unknown, IncomingRequestCfProperties<unknown>>,
3838
// @ts-expect-error This will exist in Cloudflare
3939
context: event.platform.context,
40+
// We don't want to capture errors here, as we want to capture them in the `sentryHandle` handler
41+
// where we can distinguish between redirects and actual errors.
42+
captureErrors: false,
4043
},
4144
() => resolve(event),
4245
);

packages/sveltekit/test/worker/cloudflare.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ describe('initCloudflareSentryHandle', () => {
4545

4646
expect(SentryCloudflare.wrapRequestHandler).toHaveBeenCalledTimes(1);
4747
expect(SentryCloudflare.wrapRequestHandler).toHaveBeenCalledWith(
48-
{ options: expect.objectContaining({ dsn: options.dsn }), request, context },
48+
{ options: expect.objectContaining({ dsn: options.dsn }), request, context, captureErrors: false },
4949
expect.any(Function),
5050
);
5151

0 commit comments

Comments
 (0)