Skip to content
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
37 changes: 8 additions & 29 deletions packages/node/src/integrations/onunhandledrejection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,36 +46,15 @@ export class OnUnhandledRejection implements Integration {
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any
public sendUnhandledPromise(reason: any, promise: any): void {
const hub = getCurrentHub();

if (!hub.getIntegration(OnUnhandledRejection)) {
this._handleRejection(reason);
return;
}

/* eslint-disable @typescript-eslint/no-unsafe-member-access */
const context = (promise.domain && promise.domain.sentryContext) || {};

hub.withScope((scope: Scope) => {
scope.setExtra('unhandledPromiseRejection', true);

// Preserve backwards compatibility with raven-node for now
if (context.user) {
scope.setUser(context.user);
}
if (context.tags) {
scope.setTags(context.tags);
}
if (context.extra) {
scope.setExtras(context.extra);
}

hub.captureException(reason, {
originalException: promise,
data: { mechanism: { handled: false, type: 'onunhandledrejection' } },
if (hub.getIntegration(OnUnhandledRejection)) {
hub.withScope((scope: Scope) => {
scope.setExtra('unhandledPromiseRejection', true);
hub.captureException(reason, {
originalException: promise,
data: { mechanism: { handled: false, type: 'onunhandledrejection' } },
});
});
});
/* eslint-disable @typescript-eslint/no-unsafe-member-access */

}
this._handleRejection(reason);
}

Expand Down
10 changes: 0 additions & 10 deletions packages/node/test/onunhandledrejection.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Scope } from '@sentry/core';
import { Hub } from '@sentry/hub';

import { OnUnhandledRejection } from '../src/integrations/onunhandledrejection';
Expand Down Expand Up @@ -35,21 +34,12 @@ describe('unhandled promises', () => {
};

const captureException = jest.spyOn(Hub.prototype, 'captureException');
const setUser = jest.spyOn(Scope.prototype, 'setUser');
const setExtra = jest.spyOn(Scope.prototype, 'setExtra');
const setExtras = jest.spyOn(Scope.prototype, 'setExtras');
const setTags = jest.spyOn(Scope.prototype, 'setTags');

integration.sendUnhandledPromise('bla', promise);

expect(captureException.mock.calls[0][1]?.data).toEqual({
mechanism: { handled: false, type: 'onunhandledrejection' },
});
expect(captureException.mock.calls[0][0]).toBe('bla');
expect(setUser.mock.calls[0][0]).toEqual({ id: 1 });
expect(setExtra.mock.calls[0]).toEqual(['unhandledPromiseRejection', true]);

expect(setExtras.mock.calls[0]).toEqual([{ extra: '1' }]);
expect(setTags.mock.calls[0]).toEqual([{ tag: '2' }]);
});
});