Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(node): report errorMiddleware errors as unhandled #8048

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 });
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Idk what the type here should be. I was going to write "express", but this middleware can be used by many different libraries, unlike the sveltkit and angular integrations.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think middleware is fine for this, makes sense to me!

return event;
});

const eventId = captureException(error);
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
(res as any).sentry = eventId;
Expand Down