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
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ test('sends an error', async ({ page }) => {
type: 'Error',
value: 'Error thrown from Angular 17 E2E test app',
mechanism: {
type: 'angular',
type: 'auto.function.angular.error_handler',
handled: false,
},
},
Expand Down Expand Up @@ -54,7 +54,7 @@ test('assigns the correct transaction value after a navigation', async ({ page }
type: 'Error',
value: 'Error thrown from user page',
mechanism: {
type: 'angular',
type: 'auto.function.angular.error_handler',
handled: false,
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ test('sends an error', async ({ page }) => {
type: 'Error',
value: 'Error thrown from Angular 18 E2E test app',
mechanism: {
type: 'angular',
type: 'auto.function.angular.error_handler',
handled: false,
},
},
Expand Down Expand Up @@ -54,7 +54,7 @@ test('assigns the correct transaction value after a navigation', async ({ page }
type: 'Error',
value: 'Error thrown from user page',
mechanism: {
type: 'angular',
type: 'auto.function.angular.error_handler',
handled: false,
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ test('sends an error', async ({ page }) => {
type: 'Error',
value: 'Error thrown from Angular 18 E2E test app',
mechanism: {
type: 'angular',
type: 'auto.function.angular.error_handler',
handled: false,
},
},
Expand Down Expand Up @@ -54,7 +54,7 @@ test('assigns the correct transaction value after a navigation', async ({ page }
type: 'Error',
value: 'Error thrown from user page',
mechanism: {
type: 'angular',
type: 'auto.function.angular.error_handler',
handled: false,
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ test('sends an error', async ({ page }) => {
type: 'Error',
value: 'Error thrown from Angular 20 E2E test app',
mechanism: {
type: 'angular',
type: 'auto.function.angular.error_handler',
handled: false,
},
},
Expand Down Expand Up @@ -54,7 +54,7 @@ test('assigns the correct transaction value after a navigation', async ({ page }
type: 'Error',
value: 'Error thrown from user page',
mechanism: {
type: 'angular',
type: 'auto.function.angular.error_handler',
handled: false,
},
},
Expand Down
2 changes: 1 addition & 1 deletion packages/angular/src/errorhandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class SentryErrorHandler implements AngularErrorHandler, OnDestroy {
// Capture handled exception and send it to Sentry.
const eventId = runOutsideAngular(() =>
Sentry.captureException(extractedError, {
mechanism: { type: 'angular', handled: false },
mechanism: { type: 'auto.function.angular.error_handler', handled: false },
}),
);

Expand Down
40 changes: 29 additions & 11 deletions packages/angular/test/errorhandler.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { HttpErrorResponse } from '@angular/common/http';
import * as SentryBrowser from '@sentry/browser';
import type { Client, Event } from '@sentry/core';
import { vi } from 'vitest';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { createErrorHandler, SentryErrorHandler } from '../src/errorhandler';

const captureExceptionSpy = vi.spyOn(SentryBrowser, 'captureException');

vi.spyOn(console, 'error').mockImplementation(() => {});

const captureExceptionEventHint = {
mechanism: { handled: false, type: 'angular' },
mechanism: { handled: false, type: 'auto.function.angular.error_handler' },
};

class CustomError extends Error {
Expand Down Expand Up @@ -71,15 +71,19 @@ describe('SentryErrorHandler', () => {
createErrorHandler().handleError(str);

expect(captureExceptionSpy).toHaveBeenCalledTimes(1);
expect(captureExceptionSpy).toHaveBeenCalledWith(str, { mechanism: { handled: false, type: 'angular' } });
expect(captureExceptionSpy).toHaveBeenCalledWith(str, {
mechanism: { handled: false, type: 'auto.function.angular.error_handler' },
});
});

it('extracts an empty Error', () => {
const err = new Error();
createErrorHandler().handleError(err);

expect(captureExceptionSpy).toHaveBeenCalledTimes(1);
expect(captureExceptionSpy).toHaveBeenCalledWith(err, { mechanism: { handled: false, type: 'angular' } });
expect(captureExceptionSpy).toHaveBeenCalledWith(err, {
mechanism: { handled: false, type: 'auto.function.angular.error_handler' },
});
});

it('extracts a non-empty Error', () => {
Expand All @@ -88,7 +92,9 @@ describe('SentryErrorHandler', () => {
createErrorHandler().handleError(err);

expect(captureExceptionSpy).toHaveBeenCalledTimes(1);
expect(captureExceptionSpy).toHaveBeenCalledWith(err, { mechanism: { handled: false, type: 'angular' } });
expect(captureExceptionSpy).toHaveBeenCalledWith(err, {
mechanism: { handled: false, type: 'auto.function.angular.error_handler' },
});
});

it('extracts an error-like object without stack', () => {
Expand Down Expand Up @@ -169,7 +175,9 @@ describe('SentryErrorHandler', () => {
createErrorHandler().handleError(err);

expect(captureExceptionSpy).toHaveBeenCalledTimes(1);
expect(captureExceptionSpy).toHaveBeenCalledWith(err, { mechanism: { handled: false, type: 'angular' } });
expect(captureExceptionSpy).toHaveBeenCalledWith(err, {
mechanism: { handled: false, type: 'auto.function.angular.error_handler' },
});
});

it('extracts an instance of class not extending Error but that has an error-like shape', () => {
Expand All @@ -178,7 +186,9 @@ describe('SentryErrorHandler', () => {
createErrorHandler().handleError(err);

expect(captureExceptionSpy).toHaveBeenCalledTimes(1);
expect(captureExceptionSpy).toHaveBeenCalledWith(err, { mechanism: { handled: false, type: 'angular' } });
expect(captureExceptionSpy).toHaveBeenCalledWith(err, {
mechanism: { handled: false, type: 'auto.function.angular.error_handler' },
});
});

it('extracts an instance of a class that does not extend Error and does not have an error-like shape', () => {
Expand Down Expand Up @@ -251,7 +261,9 @@ describe('SentryErrorHandler', () => {
createErrorHandler().handleError(err);

expect(captureExceptionSpy).toHaveBeenCalledTimes(1);
expect(captureExceptionSpy).toHaveBeenCalledWith(ngErr, { mechanism: { handled: false, type: 'angular' } });
expect(captureExceptionSpy).toHaveBeenCalledWith(ngErr, {
mechanism: { handled: false, type: 'auto.function.angular.error_handler' },
});
});

it('extracts an `HttpErrorResponse` with `Error`', () => {
Expand All @@ -261,7 +273,9 @@ describe('SentryErrorHandler', () => {
createErrorHandler().handleError(err);

expect(captureExceptionSpy).toHaveBeenCalledTimes(1);
expect(captureExceptionSpy).toHaveBeenCalledWith(httpErr, { mechanism: { handled: false, type: 'angular' } });
expect(captureExceptionSpy).toHaveBeenCalledWith(httpErr, {
mechanism: { handled: false, type: 'auto.function.angular.error_handler' },
});
});

it('extracts an `HttpErrorResponse` with `ErrorEvent`', () => {
Expand Down Expand Up @@ -431,7 +445,9 @@ describe('SentryErrorHandler', () => {
createErrorHandler().handleError(err);

expect(captureExceptionSpy).toHaveBeenCalledTimes(1);
expect(captureExceptionSpy).toHaveBeenCalledWith(err, { mechanism: { handled: false, type: 'angular' } });
expect(captureExceptionSpy).toHaveBeenCalledWith(err, {
mechanism: { handled: false, type: 'auto.function.angular.error_handler' },
});
});

it('extracts an `HttpErrorResponse` with an instance of class not extending Error but that has an error-like shape', () => {
Expand All @@ -441,7 +457,9 @@ describe('SentryErrorHandler', () => {
createErrorHandler().handleError(err);

expect(captureExceptionSpy).toHaveBeenCalledTimes(1);
expect(captureExceptionSpy).toHaveBeenCalledWith(innerErr, { mechanism: { handled: false, type: 'angular' } });
expect(captureExceptionSpy).toHaveBeenCalledWith(innerErr, {
mechanism: { handled: false, type: 'auto.function.angular.error_handler' },
});
});

it('extracts an `HttpErrorResponse` with an instance of a class that does not extend Error and does not have an error-like shape', () => {
Expand Down