Skip to content

'Redirect' captured as exception with keys: location, status #16847

Closed

Description

@RaniSputnik

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/sveltekit

SDK Version

9.35.0

Framework Version

Sveltekit 2.17.1

Link to Sentry event

No response

Reproduction Example/SDK Setup

RaniSputnik/sentry-issues@redirect-captured-as-exception

Steps to Reproduce

Redirect using the Sveltekit server handle hook. Eg.

import { sequence } from '@sveltejs/kit/hooks';
import { handleErrorWithSentry, sentryHandle, initCloudflareSentryHandle } from '@sentry/sveltekit';
import { redirect, type Handle } from '@sveltejs/kit';

const redirectToSentryPage: Handle = async ({ event, resolve }): Promise<Response> => {
	if (!event.request.url.includes("sentry")) {
		return redirect(303, "sentry-example-page");
	}
	return resolve(event)
}


// If you have custom handlers, make sure to place them after `sentryHandle()` in the `sequence` function.
export const handle = sequence(
	initCloudflareSentryHandle({ /* dsn etc */ }),
	sentryHandle(),
	redirectToSentryPage,
);

// If you have a custom error handler, pass it to `handleErrorWithSentry`
export const handleError = handleErrorWithSentry();

Deploy to Cloudflare workers. (I haven’t tested whether this impacts other adaptors eg. Vercel)

Visit a page that triggers a redirect (eg. /foo in my example repo).

Expected Result

No error is captured by Sentry.

Actual Result

An error is captured by Sentry with the message 'Redirect' captured as exception with keys: location, status.

Image

It also seems like the issue fingerprint is changed by the path of the user and exactly when the redirect was raised, so this ends up having quite a large impact on our production instance. Multiple issues are opened for the same root cause:

Image

Activity

  1. moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Jul 8, 2025
  2. Lms24 commented on Jul 9, 2025

    @Lms24
    Member

    Hey again @RaniSputnik, thanks for reporting! Taking a look at your reproduction (much appreciated, thank you!) and will report back.

  3. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Jul 9, 2025
  4. Lms24 commented on Jul 9, 2025

    @Lms24
    Member

    The issue here is indeed Cloudflare specific because the initCloudflareSentryHandle function internally adds a wrapper around the cloudflare worker request handler. This wrapper was originally designed to be used in pure Cloudflare worker functions, so it also captures errors and sends them to Sentry. However, because it isn't tailored to SvelteKit, it doesn't filter out thrown redirect(...)s.

    I also noticed that this sometimes caused errors being caught twice, once by the CF handler, once by sentryHandle.

    I'll open a PR to fix this. Probably gonna add an option to the wrapper to opt out of capturing errors, meaning, we'll let the SvelteKit SDK handle this.

  5. Lms24 commented on Jul 9, 2025

    @Lms24
    Member

    I opened #16852 and #16853 to fix this. Thanks a lot for reporting!

  6. self-assigned this
    on Jul 9, 2025
  7. github-actions commented on Jul 10, 2025

    @github-actions
    Contributor

    A PR closing this issue has just been released 🚀

    This issue was referenced by PR #16853, which was included in the 9.37.0 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions