Skip to content

Commit

Permalink
Don't capture errors for redirects
Browse files Browse the repository at this point in the history
  • Loading branch information
lforst committed Aug 30, 2023
1 parent 7e9415d commit ea87659
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions packages/nextjs/src/common/wrapRouteHandlerWithSentry.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { addTracingExtensions, captureException, flush, getCurrentHub, runWithAsyncContext, trace } from '@sentry/core';
import { addExceptionMechanism, tracingContextFromHeaders } from '@sentry/utils';

import { isRedirectNavigationError } from './nextNavigationErrorUtils';
import type { RouteHandlerContext } from './types';
import { platformSupportsStreaming } from './utils/platformSupportsStreaming';

Expand Down Expand Up @@ -53,16 +54,19 @@ export function wrapRouteHandlerWithSentry<F extends (...args: any[]) => any>(
return response;
},
error => {
captureException(error, scope => {
scope.addEventProcessor(event => {
addExceptionMechanism(event, {
handled: false,
// Next.js throws errors when calling `redirect()`. We don't wanna report these.
if (!isRedirectNavigationError(error)) {
captureException(error, scope => {
scope.addEventProcessor(event => {
addExceptionMechanism(event, {
handled: false,
});
return event;
});
return event;
});

return scope;
});
return scope;
});
}
},
);
} finally {
Expand Down

0 comments on commit ea87659

Please sign in to comment.