`NEXT_REDIRECT` error to be reported as an Unhandled Error in Server Action redirect function.
Is there an existing issue for this?
- [x] I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues
- [x] I have reviewed the documentation https://docs.sentry.io/
- [x] 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/nextjs
SDK Version
8.40.0
Framework Version
React 19.0.0-rc-66855b96-20241106 & Next.js 15.0.3
Link to Sentry event
https://nekoyasan.sentry.io/issues/6082760807/events/a7a626e05026406bb3d13a68e8270c92/
Reproduction Example/SDK Setup
Reproduction Example: https://github.com/NEKOYASAN/next-sentry-redirect-minimum-repro
Reproduction Steps (From completely empty)
pnpm create next-appnpx @sentry/wizard@latest -i nextjs --saas- add Server Action & Components (redirect function in Server Action)
Steps to Reproduce
pnpm run buildpnpm run start- Click
Redirect to example pageButton - Redirects normally to
/example(butNEXT_REDIRECTError is reported to Sentry)
Expected Result
Maybe NEXT_REDIRECT should not be reported to Sentry.
Actual Result
Server Action reports NEXT_REDIRECT as Unhandled Error.
but it does not seem to be reported in page.tsx, so there seems to be no problem.
Maybe ref: #7641 and #10038
One way to prevent reporting is to add beforeSend to sentry.client.config.ts
Sentry.init({
/* etc... */
beforeSend(event, hint) {
const error = hint.originalException as Error & { digest?: unknown };
if (
error &&
error.digest &&
typeof error.digest === 'string' &&
error.digest.startsWith('NEXT_REDIRECT;')
) {
return null;
}
return event;
},
/* etc... */
});
NEXT_REDIRECT should have been absorbed by the client-side redirect error boundary, but was somehow reported to Sentry as an Unhandled Error.
I don't remember seeing it on Next.js 15-rc0 + sentry/nextjs 8.27.0 , so maybe something changed between Next.js rc1,2 ~ 15.0.3
One way to prevent reporting is to add
beforeSendtosentry.client.config.tsSentry.init({ /* etc... / beforeSend(event, hint) { const error = hint.originalException as Error & { digest?: unknown }; if ( error && error.digest && typeof error.digest === 'string' && error.digest.startsWith('NEXT_REDIRECT;') ) { return null; } return event; }, / etc... */ });
This did the trick for me, thank you.
A PR closing this issue has just been released 🚀
This issue was referenced by PR #14440, which was included in the 8.41.0 release.