Skip to content

Commit

Permalink
fix(node): report errorMiddleware errors as unhandled (#8048)
Browse files Browse the repository at this point in the history
  • Loading branch information
chdsbd authored Jul 1, 2023
1 parent cf8c072 commit 3625fb1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
6 changes: 6 additions & 0 deletions packages/node/src/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
import type { Span } from '@sentry/types';
import type { AddRequestDataToEventOptions } from '@sentry/utils';
import {
addExceptionMechanism,
addRequestDataToTransaction,
baggageHeaderToDynamicSamplingContext,
dropUndefinedKeys,
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 3625fb1

Please sign in to comment.