11import { HttpErrorResponse } from '@angular/common/http' ;
22import * as SentryBrowser from '@sentry/browser' ;
33import type { Client , Event } from '@sentry/core' ;
4- import { vi } from 'vitest' ;
4+ import { afterEach , beforeEach , describe , expect , it , vi } from 'vitest' ;
55import { createErrorHandler , SentryErrorHandler } from '../src/errorhandler' ;
66
77const captureExceptionSpy = vi . spyOn ( SentryBrowser , 'captureException' ) ;
88
99vi . spyOn ( console , 'error' ) . mockImplementation ( ( ) => { } ) ;
1010
1111const captureExceptionEventHint = {
12- mechanism : { handled : false , type : 'angular' } ,
12+ mechanism : { handled : false , type : 'auto.function. angular.error_handler ' } ,
1313} ;
1414
1515class CustomError extends Error {
@@ -71,15 +71,19 @@ describe('SentryErrorHandler', () => {
7171 createErrorHandler ( ) . handleError ( str ) ;
7272
7373 expect ( captureExceptionSpy ) . toHaveBeenCalledTimes ( 1 ) ;
74- expect ( captureExceptionSpy ) . toHaveBeenCalledWith ( str , { mechanism : { handled : false , type : 'angular' } } ) ;
74+ expect ( captureExceptionSpy ) . toHaveBeenCalledWith ( str , {
75+ mechanism : { handled : false , type : 'auto.function.angular.error_handler' } ,
76+ } ) ;
7577 } ) ;
7678
7779 it ( 'extracts an empty Error' , ( ) => {
7880 const err = new Error ( ) ;
7981 createErrorHandler ( ) . handleError ( err ) ;
8082
8183 expect ( captureExceptionSpy ) . toHaveBeenCalledTimes ( 1 ) ;
82- expect ( captureExceptionSpy ) . toHaveBeenCalledWith ( err , { mechanism : { handled : false , type : 'angular' } } ) ;
84+ expect ( captureExceptionSpy ) . toHaveBeenCalledWith ( err , {
85+ mechanism : { handled : false , type : 'auto.function.angular.error_handler' } ,
86+ } ) ;
8387 } ) ;
8488
8589 it ( 'extracts a non-empty Error' , ( ) => {
@@ -88,7 +92,9 @@ describe('SentryErrorHandler', () => {
8892 createErrorHandler ( ) . handleError ( err ) ;
8993
9094 expect ( captureExceptionSpy ) . toHaveBeenCalledTimes ( 1 ) ;
91- expect ( captureExceptionSpy ) . toHaveBeenCalledWith ( err , { mechanism : { handled : false , type : 'angular' } } ) ;
95+ expect ( captureExceptionSpy ) . toHaveBeenCalledWith ( err , {
96+ mechanism : { handled : false , type : 'auto.function.angular.error_handler' } ,
97+ } ) ;
9298 } ) ;
9399
94100 it ( 'extracts an error-like object without stack' , ( ) => {
@@ -169,7 +175,9 @@ describe('SentryErrorHandler', () => {
169175 createErrorHandler ( ) . handleError ( err ) ;
170176
171177 expect ( captureExceptionSpy ) . toHaveBeenCalledTimes ( 1 ) ;
172- expect ( captureExceptionSpy ) . toHaveBeenCalledWith ( err , { mechanism : { handled : false , type : 'angular' } } ) ;
178+ expect ( captureExceptionSpy ) . toHaveBeenCalledWith ( err , {
179+ mechanism : { handled : false , type : 'auto.function.angular.error_handler' } ,
180+ } ) ;
173181 } ) ;
174182
175183 it ( 'extracts an instance of class not extending Error but that has an error-like shape' , ( ) => {
@@ -178,7 +186,9 @@ describe('SentryErrorHandler', () => {
178186 createErrorHandler ( ) . handleError ( err ) ;
179187
180188 expect ( captureExceptionSpy ) . toHaveBeenCalledTimes ( 1 ) ;
181- expect ( captureExceptionSpy ) . toHaveBeenCalledWith ( err , { mechanism : { handled : false , type : 'angular' } } ) ;
189+ expect ( captureExceptionSpy ) . toHaveBeenCalledWith ( err , {
190+ mechanism : { handled : false , type : 'auto.function.angular.error_handler' } ,
191+ } ) ;
182192 } ) ;
183193
184194 it ( 'extracts an instance of a class that does not extend Error and does not have an error-like shape' , ( ) => {
@@ -251,7 +261,9 @@ describe('SentryErrorHandler', () => {
251261 createErrorHandler ( ) . handleError ( err ) ;
252262
253263 expect ( captureExceptionSpy ) . toHaveBeenCalledTimes ( 1 ) ;
254- expect ( captureExceptionSpy ) . toHaveBeenCalledWith ( ngErr , { mechanism : { handled : false , type : 'angular' } } ) ;
264+ expect ( captureExceptionSpy ) . toHaveBeenCalledWith ( ngErr , {
265+ mechanism : { handled : false , type : 'auto.function.angular.error_handler' } ,
266+ } ) ;
255267 } ) ;
256268
257269 it ( 'extracts an `HttpErrorResponse` with `Error`' , ( ) => {
@@ -261,7 +273,9 @@ describe('SentryErrorHandler', () => {
261273 createErrorHandler ( ) . handleError ( err ) ;
262274
263275 expect ( captureExceptionSpy ) . toHaveBeenCalledTimes ( 1 ) ;
264- expect ( captureExceptionSpy ) . toHaveBeenCalledWith ( httpErr , { mechanism : { handled : false , type : 'angular' } } ) ;
276+ expect ( captureExceptionSpy ) . toHaveBeenCalledWith ( httpErr , {
277+ mechanism : { handled : false , type : 'auto.function.angular.error_handler' } ,
278+ } ) ;
265279 } ) ;
266280
267281 it ( 'extracts an `HttpErrorResponse` with `ErrorEvent`' , ( ) => {
@@ -431,7 +445,9 @@ describe('SentryErrorHandler', () => {
431445 createErrorHandler ( ) . handleError ( err ) ;
432446
433447 expect ( captureExceptionSpy ) . toHaveBeenCalledTimes ( 1 ) ;
434- expect ( captureExceptionSpy ) . toHaveBeenCalledWith ( err , { mechanism : { handled : false , type : 'angular' } } ) ;
448+ expect ( captureExceptionSpy ) . toHaveBeenCalledWith ( err , {
449+ mechanism : { handled : false , type : 'auto.function.angular.error_handler' } ,
450+ } ) ;
435451 } ) ;
436452
437453 it ( 'extracts an `HttpErrorResponse` with an instance of class not extending Error but that has an error-like shape' , ( ) => {
@@ -441,7 +457,9 @@ describe('SentryErrorHandler', () => {
441457 createErrorHandler ( ) . handleError ( err ) ;
442458
443459 expect ( captureExceptionSpy ) . toHaveBeenCalledTimes ( 1 ) ;
444- expect ( captureExceptionSpy ) . toHaveBeenCalledWith ( innerErr , { mechanism : { handled : false , type : 'angular' } } ) ;
460+ expect ( captureExceptionSpy ) . toHaveBeenCalledWith ( innerErr , {
461+ mechanism : { handled : false , type : 'auto.function.angular.error_handler' } ,
462+ } ) ;
445463 } ) ;
446464
447465 it ( 'extracts an `HttpErrorResponse` with an instance of a class that does not extend Error and does not have an error-like shape' , ( ) => {
0 commit comments