diff --git a/packages/node-integration-tests/suites/express/handle-error/test.ts b/packages/node-integration-tests/suites/express/handle-error/test.ts index e8be4081203c..d9eb59a72785 100644 --- a/packages/node-integration-tests/suites/express/handle-error/test.ts +++ b/packages/node-integration-tests/suites/express/handle-error/test.ts @@ -11,8 +11,8 @@ test('should capture and send Express controller error.', async () => { values: [ { mechanism: { - type: 'generic', - handled: true, + type: 'middleware', + handled: false, }, type: 'Error', value: 'test_error', diff --git a/packages/node/src/handlers.ts b/packages/node/src/handlers.ts index 95a4cfe65e38..c23130f4b0cd 100644 --- a/packages/node/src/handlers.ts +++ b/packages/node/src/handlers.ts @@ -10,6 +10,7 @@ import { import type { Span } from '@sentry/types'; import type { AddRequestDataToEventOptions } from '@sentry/utils'; import { + addExceptionMechanism, addRequestDataToTransaction, baggageHeaderToDynamicSamplingContext, dropUndefinedKeys, @@ -304,6 +305,11 @@ export function errorHandler(options?: { } } + _scope.addEventProcessor(event => { + addExceptionMechanism(event, { type: 'middleware', handled: false }); + return event; + }); + const eventId = captureException(error); // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access (res as any).sentry = eventId;