Repository navigation
Closed
Description
Is there an existing issue for this?
- I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues
- I have reviewed the documentation https://docs.sentry.io/
- I am using the latest SDK release https://github.com/getsentry/sentry-javascript/releases
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.
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:

Metadata
Metadata
Assignees
Projects
- StatusShow more project fieldsNo status
Activity
Lms24 commentedon Jul 9, 2025
Hey again @RaniSputnik, thanks for reporting! Taking a look at your reproduction (much appreciated, thank you!) and will report back.
Lms24 commentedon Jul 9, 2025
The issue here is indeed Cloudflare specific because the
initCloudflareSentryHandlefunction 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 thrownredirect(...)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.
Lms24 commentedon Jul 9, 2025
I opened #16852 and #16853 to fix this. Thanks a lot for reporting!
github-actions commentedon Jul 10, 2025
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.