Skip to content

Commit 29ef20e

Browse files
authored
feat(integrations): Mark errors caught from HttpClient and CaptureConsole integrations as unhandled (#8891)
Mark errors caught from optional integrations * `HttpClient` * `CaptureConsole` as unhandled. For more details see #8890, #6073
1 parent 39401f0 commit 29ef20e

File tree

9 files changed

+46
-6
lines changed

9 files changed

+46
-6
lines changed

packages/browser-integration-tests/suites/integrations/httpclient/axios/test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ sentryTest(
3838
value: 'HTTP Client Error with status code: 500',
3939
mechanism: {
4040
type: 'http.client',
41-
handled: true,
41+
handled: false,
4242
},
4343
},
4444
],

packages/browser-integration-tests/suites/integrations/httpclient/fetch/simple/test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ sentryTest(
3838
value: 'HTTP Client Error with status code: 500',
3939
mechanism: {
4040
type: 'http.client',
41-
handled: true,
41+
handled: false,
4242
},
4343
},
4444
],

packages/browser-integration-tests/suites/integrations/httpclient/fetch/withRequest/test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ sentryTest('works with a Request passed in', async ({ getLocalTestPath, page })
3636
value: 'HTTP Client Error with status code: 500',
3737
mechanism: {
3838
type: 'http.client',
39-
handled: true,
39+
handled: false,
4040
},
4141
},
4242
],

packages/browser-integration-tests/suites/integrations/httpclient/fetch/withRequestAndBodyAndOptions/test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ sentryTest(
3838
value: 'HTTP Client Error with status code: 500',
3939
mechanism: {
4040
type: 'http.client',
41-
handled: true,
41+
handled: false,
4242
},
4343
},
4444
],

packages/browser-integration-tests/suites/integrations/httpclient/fetch/withRequestAndOptions/test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ sentryTest('works with a Request (without body) & options passed in', async ({ g
3636
value: 'HTTP Client Error with status code: 500',
3737
mechanism: {
3838
type: 'http.client',
39-
handled: true,
39+
handled: false,
4040
},
4141
},
4242
],

packages/browser-integration-tests/suites/integrations/httpclient/xhr/test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ sentryTest(
3838
value: 'HTTP Client Error with status code: 500',
3939
mechanism: {
4040
type: 'http.client',
41-
handled: true,
41+
handled: false,
4242
},
4343
},
4444
],

packages/integrations/src/captureconsole.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { EventProcessor, Hub, Integration } from '@sentry/types';
22
import {
3+
addExceptionMechanism,
34
addInstrumentationHandler,
45
CONSOLE_LEVELS,
56
GLOBAL_OBJ,
@@ -64,6 +65,12 @@ function consoleHandler(hub: Hub, args: unknown[], level: string): void {
6465
scope.setExtra('arguments', args);
6566
scope.addEventProcessor(event => {
6667
event.logger = 'console';
68+
69+
addExceptionMechanism(event, {
70+
handled: false,
71+
type: 'console',
72+
});
73+
6774
return event;
6875
});
6976

packages/integrations/src/httpclient.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,7 @@ export class HttpClient implements Integration {
416416

417417
addExceptionMechanism(event, {
418418
type: 'http.client',
419+
handled: false,
419420
});
420421

421422
return event;

packages/integrations/test/captureconsole.test.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,4 +397,36 @@ describe('CaptureConsole setup', () => {
397397
GLOBAL_OBJ.console.log('some message');
398398
}).not.toThrow();
399399
});
400+
401+
it("marks captured exception's mechanism as unhandled", () => {
402+
// const addExceptionMechanismSpy = jest.spyOn(utils, 'addExceptionMechanism');
403+
404+
const captureConsoleIntegration = new CaptureConsole({ levels: ['error'] });
405+
const mockHub = getMockHub(captureConsoleIntegration);
406+
captureConsoleIntegration.setupOnce(
407+
() => undefined,
408+
() => mockHub,
409+
);
410+
411+
const mockScope = mockHub.getScope();
412+
413+
const someError = new Error('some error');
414+
GLOBAL_OBJ.console.error(someError);
415+
416+
const addedEventProcessor = (mockScope.addEventProcessor as jest.Mock).mock.calls[0][0];
417+
const someEvent: Event = {
418+
exception: {
419+
values: [{}],
420+
},
421+
};
422+
addedEventProcessor(someEvent);
423+
424+
expect(mockHub.captureException).toHaveBeenCalledTimes(1);
425+
expect(mockScope.addEventProcessor).toHaveBeenCalledTimes(1);
426+
427+
expect(someEvent.exception?.values?.[0].mechanism).toEqual({
428+
handled: false,
429+
type: 'console',
430+
});
431+
});
400432
});

0 commit comments

Comments
 (0)