@@ -7,7 +7,7 @@ import { Operation, NextLink, ServerError } from '@apollo/client/core';
77import { GraphQLError } from 'graphql' ;
88import { cache } from './cache' ;
99import { GET_LOCAL_SIGNED_IN_STATUS } from '../components/App/gql' ;
10- import sentryMetrics from 'fxa-shared/ sentry/browser' ;
10+ import * as Sentry from '@ sentry/browser' ;
1111
1212describe ( 'errorHandler' , ( ) => {
1313 beforeAll ( ( ) => {
@@ -26,8 +26,10 @@ describe('errorHandler', () => {
2626 originalError : { error : 'Unauthorized' } ,
2727 } ) ,
2828 ] ,
29- operation : null as any as Operation ,
30- forward : null as any as NextLink ,
29+ operation : {
30+ operationName : 'foo' ,
31+ } as Operation ,
32+ forward : jest . fn ( ) ,
3133 } ;
3234
3335 errorHandler ( errorResponse ) ;
@@ -38,21 +40,55 @@ describe('errorHandler', () => {
3840 } ) ;
3941 } ) ;
4042
43+ it ( 'adds breadcrumb on graphql error' , ( ) => {
44+ const gqlError = new GraphQLError ( 'Foo' , null , null , null , null , null , {
45+ originalError : { error : 'Boom' } ,
46+ } ) ;
47+ const errorResponse : ErrorResponse = {
48+ graphQLErrors : [ gqlError ] ,
49+ operation : {
50+ operationName : 'Foo' ,
51+ } as Operation ,
52+ forward : jest . fn ( ) ,
53+ } ;
54+
55+ const addBreadcrumbMock = jest . fn ( ) ;
56+ jest . spyOn ( Sentry , 'addBreadcrumb' ) . mockImplementation ( addBreadcrumbMock ) ;
57+
58+ errorHandler ( errorResponse ) ;
59+
60+ expect ( addBreadcrumbMock ) . toHaveBeenCalledWith ( {
61+ category : 'graphql.error' ,
62+ message : 'Foo' ,
63+ level : 'error' ,
64+ data : {
65+ operation : 'Foo' ,
66+ graphQLError : gqlError ,
67+ } ,
68+ } ) ;
69+ } ) ;
70+
4171 it ( 'logs network errors to Sentry' , ( ) => {
4272 let networkError : any ;
4373 networkError = new Error ( 'Network error' ) as ServerError ;
4474 const errorResponse : ErrorResponse = {
4575 networkError,
46- operation : null as any as Operation ,
47- forward : null as any as NextLink ,
76+ operation : {
77+ operationName : 'foo' ,
78+ } as any as Operation ,
79+ forward : jest . fn ( ) as NextLink ,
4880 } ;
4981 const captureExceptionMock = jest . fn ( ) ;
5082 jest
51- . spyOn ( sentryMetrics , 'captureException' )
83+ . spyOn ( Sentry , 'captureException' )
5284 . mockImplementation ( captureExceptionMock ) ;
5385
5486 errorHandler ( errorResponse ) ;
5587
56- expect ( captureExceptionMock ) . toHaveBeenCalledWith ( networkError ) ;
88+ expect ( captureExceptionMock ) . toHaveBeenCalledWith ( networkError , {
89+ extra : {
90+ operation : 'foo' ,
91+ } ,
92+ } ) ;
5793 } ) ;
5894} ) ;
0 commit comments