Skip to content

Commit

Permalink
hope to fix "faulty route handlers"
Browse files Browse the repository at this point in the history
  • Loading branch information
lforst committed Mar 19, 2024
1 parent 0f68238 commit 815b156
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ test('Should record exceptions and transactions for faulty route handlers', asyn
const routehandlerTransaction = await routehandlerTransactionPromise;
const routehandlerError = await errorEventPromise;

expect(routehandlerTransaction.contexts?.trace?.status).toBe('internal_error');
expect(routehandlerTransaction.contexts?.trace?.status).toBe('unknown_error');
expect(routehandlerTransaction.contexts?.trace?.op).toBe('http.server');

expect(routehandlerError.exception?.values?.[0].value).toBe('route-handler-error');
Expand Down
8 changes: 6 additions & 2 deletions packages/nextjs/src/common/wrapRouteHandlerWithSentry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
} from '@sentry/core';
import { winterCGHeadersToDict } from '@sentry/utils';

import { isRedirectNavigationError } from './nextNavigationErrorUtils';
import { isNotFoundNavigationError, isRedirectNavigationError } from './nextNavigationErrorUtils';
import type { RouteHandlerContext } from './types';
import { platformSupportsStreaming } from './utils/platformSupportsStreaming';
import { flushQueue } from './utils/responseEnd';
Expand Down Expand Up @@ -57,7 +57,11 @@ export function wrapRouteHandlerWithSentry<F extends (...args: any[]) => any>(
() => originalFunction.apply(thisArg, args),
error => {
// Next.js throws errors when calling `redirect()`. We don't wanna report these.
if (!isRedirectNavigationError(error)) {
if (isRedirectNavigationError(error)) {
// Don't do anything
} else if (isNotFoundNavigationError(error)) {
setHttpStatus(span, 404);
} else {
captureException(error, {
mechanism: {
handled: false,
Expand Down

0 comments on commit 815b156

Please sign in to comment.