Skip to content

Commit 815b156

Browse files
author
Luca Forstner
committed
hope to fix "faulty route handlers"
1 parent 0f68238 commit 815b156

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

dev-packages/e2e-tests/test-applications/nextjs-app-dir/tests/route-handlers.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ test('Should record exceptions and transactions for faulty route handlers', asyn
4848
const routehandlerTransaction = await routehandlerTransactionPromise;
4949
const routehandlerError = await errorEventPromise;
5050

51-
expect(routehandlerTransaction.contexts?.trace?.status).toBe('internal_error');
51+
expect(routehandlerTransaction.contexts?.trace?.status).toBe('unknown_error');
5252
expect(routehandlerTransaction.contexts?.trace?.op).toBe('http.server');
5353

5454
expect(routehandlerError.exception?.values?.[0].value).toBe('route-handler-error');

packages/nextjs/src/common/wrapRouteHandlerWithSentry.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
} from '@sentry/core';
1212
import { winterCGHeadersToDict } from '@sentry/utils';
1313

14-
import { isRedirectNavigationError } from './nextNavigationErrorUtils';
14+
import { isNotFoundNavigationError, isRedirectNavigationError } from './nextNavigationErrorUtils';
1515
import type { RouteHandlerContext } from './types';
1616
import { platformSupportsStreaming } from './utils/platformSupportsStreaming';
1717
import { flushQueue } from './utils/responseEnd';
@@ -57,7 +57,11 @@ export function wrapRouteHandlerWithSentry<F extends (...args: any[]) => any>(
5757
() => originalFunction.apply(thisArg, args),
5858
error => {
5959
// Next.js throws errors when calling `redirect()`. We don't wanna report these.
60-
if (!isRedirectNavigationError(error)) {
60+
if (isRedirectNavigationError(error)) {
61+
// Don't do anything
62+
} else if (isNotFoundNavigationError(error)) {
63+
setHttpStatus(span, 404);
64+
} else {
6165
captureException(error, {
6266
mechanism: {
6367
handled: false,

0 commit comments

Comments
 (0)