Skip to content

Commit 3625fb1

Browse files
authored
fix(node): report errorMiddleware errors as unhandled (#8048)
1 parent cf8c072 commit 3625fb1

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

packages/node-integration-tests/suites/express/handle-error/test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ test('should capture and send Express controller error.', async () => {
1111
values: [
1212
{
1313
mechanism: {
14-
type: 'generic',
15-
handled: true,
14+
type: 'middleware',
15+
handled: false,
1616
},
1717
type: 'Error',
1818
value: 'test_error',

packages/node/src/handlers.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
import type { Span } from '@sentry/types';
1111
import type { AddRequestDataToEventOptions } from '@sentry/utils';
1212
import {
13+
addExceptionMechanism,
1314
addRequestDataToTransaction,
1415
baggageHeaderToDynamicSamplingContext,
1516
dropUndefinedKeys,
@@ -304,6 +305,11 @@ export function errorHandler(options?: {
304305
}
305306
}
306307

308+
_scope.addEventProcessor(event => {
309+
addExceptionMechanism(event, { type: 'middleware', handled: false });
310+
return event;
311+
});
312+
307313
const eventId = captureException(error);
308314
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
309315
(res as any).sentry = eventId;

0 commit comments

Comments
 (0)