You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
'Redirect' captured as exception with keys: location, status #16847
import{sequence}from'@sveltejs/kit/hooks';import{handleErrorWithSentry,sentryHandle,initCloudflareSentryHandle}from'@sentry/sveltekit';import{redirect,typeHandle}from'@sveltejs/kit';constredirectToSentryPage: Handle=async({ event, resolve }): Promise<Response>=>{if(!event.request.url.includes("sentry")){returnredirect(303,"sentry-example-page");}returnresolve(event)}// If you have custom handlers, make sure to place them after `sentryHandle()` in the `sequence` function.exportconsthandle=sequence(initCloudflareSentryHandle({/* dsn etc */}),sentryHandle(),redirectToSentryPage,);// If you have a custom error handler, pass it to `handleErrorWithSentry`exportconsthandleError=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:
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.
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.