@@ -34,7 +34,7 @@ describe('graphql - error handling in production', () => {
3434 {
3535 message : 'Value is required' ,
3636 extensions : {
37- code : '400 ' ,
37+ code : 'ASSERT_NOT_NULL ' ,
3838 target : 'notEmptyI'
3939 }
4040 }
@@ -43,7 +43,7 @@ describe('graphql - error handling in production', () => {
4343 expect ( response . data ) . toMatchObject ( { errors } )
4444 expect ( response . data . errors [ 0 ] . extensions ) . not . toHaveProperty ( 'stacktrace' ) // No stacktrace in production
4545 const log = console . warn . mock . calls [ 0 ] [ 1 ] || JSON . parse ( console . warn . mock . calls [ 0 ] [ 0 ] )
46- expect ( log ) . toMatchObject ( { code : '400 ' , target : 'notEmptyI' , msg : 'Value is required' } )
46+ expect ( log ) . toMatchObject ( { code : 'ASSERT_NOT_NULL ' , target : 'notEmptyI' , msg : 'Value is required' } )
4747 } )
4848
4949 test ( 'Multiple @mandatory validation errors' , async ( ) => {
@@ -62,15 +62,15 @@ describe('graphql - error handling in production', () => {
6262 {
6363 message : 'Multiple errors occurred. Please see the details for more information.' ,
6464 extensions : {
65- code : '400 ' ,
65+ code : 'MULTIPLE_ERRORS ' ,
6666 details : [
6767 {
68- code : '400 ' ,
68+ code : 'ASSERT_NOT_NULL ' ,
6969 message : 'Value is required' ,
7070 target : 'notEmptyI'
7171 } ,
7272 {
73- code : '400 ' ,
73+ code : 'ASSERT_NOT_NULL ' ,
7474 message : 'Value is required' ,
7575 target : 'notEmptyS'
7676 }
@@ -101,7 +101,7 @@ describe('graphql - error handling in production', () => {
101101 {
102102 message : 'Value 10 is not in specified range [0, 3]' ,
103103 extensions : {
104- code : '400 ' ,
104+ code : 'ASSERT_RANGE ' ,
105105 target : 'inRange'
106106 }
107107 }
@@ -127,15 +127,15 @@ describe('graphql - error handling in production', () => {
127127 {
128128 message : 'Es sind mehrere Fehler aufgetreten.' ,
129129 extensions : {
130- code : '400 ' ,
130+ code : 'MULTIPLE_ERRORS ' ,
131131 details : [
132132 {
133- code : '400 ' ,
133+ code : 'ASSERT_NOT_NULL ' ,
134134 message : 'Wert ist erforderlich' ,
135135 target : 'inRange'
136136 } ,
137137 {
138- code : '400 ' ,
138+ code : 'ASSERT_ENUM ' ,
139139 message : expect . stringContaining ( 'Value "foo" is invalid' ) ,
140140 target : 'oneOfEnumValues'
141141 }
@@ -151,12 +151,12 @@ describe('graphql - error handling in production', () => {
151151 const log = console . warn . mock . calls [ 0 ] [ 1 ] || JSON . parse ( console . warn . mock . calls [ 0 ] [ 0 ] )
152152
153153 expect ( log ) . toMatchObject ( {
154- code : '400 ' ,
154+ code : 'MULTIPLE_ERRORS ' ,
155155 msg : 'Multiple errors occurred. Please see the details for more information.' ,
156156 details : [
157- { code : '400 ' , target : 'inRange' , message : 'Value is required' } ,
157+ { code : 'ASSERT_NOT_NULL ' , target : 'inRange' , message : 'Value is required' } ,
158158 {
159- code : '400 ' ,
159+ code : 'ASSERT_ENUM ' ,
160160 target : 'oneOfEnumValues' ,
161161 message : expect . stringContaining ( 'Value "foo" is invalid' )
162162 }
@@ -314,32 +314,19 @@ describe('graphql - error handling in production', () => {
314314 `
315315 const errors = [
316316 {
317- message : 'Multiple errors occurred. Please see the details for more information. ' ,
317+ message : 'Internal Server Error ' ,
318318 extensions : {
319- code : '500' ,
320- details : [
321- {
322- code : 'Some-Custom-Code1' ,
323- message : 'Some Custom Error Message 1' ,
324- target : 'some_field'
325- } ,
326- {
327- code : 'Some-Custom-Code2' ,
328- message : 'Some Custom Error Message 2' ,
329- target : 'some_field'
330- }
331- ]
319+ code : '500'
332320 }
333321 }
334322 ]
335323 const response = await POST ( '/graphql' , { query } )
336324 expect ( response . data ) . toMatchObject ( { errors } )
337325 expect ( response . data . errors [ 0 ] . extensions ) . not . toHaveProperty ( 'stacktrace' ) // No stacktrace outside of error details
338- expect ( response . data . errors [ 0 ] . extensions . details [ 0 ] ) . not . toHaveProperty ( 'stacktrace' ) // No stacktrace in production
339- expect ( response . data . errors [ 0 ] . extensions . details [ 1 ] ) . not . toHaveProperty ( 'stacktrace' ) // No stacktrace in production
326+ expect ( response . data . errors [ 0 ] . extensions ) . not . toHaveProperty ( 'details' ) // No details since one of the errors is 5xx
340327 const log = console . error . mock . calls [ 0 ] [ 1 ] || JSON . parse ( console . error . mock . calls [ 0 ] [ 0 ] )
341328 expect ( log ) . toMatchObject ( {
342- code : '500 ' ,
329+ code : 'MULTIPLE_ERRORS ' ,
343330 msg : 'Multiple errors occurred. Please see the details for more information.' ,
344331 details : [
345332 {
@@ -411,7 +398,7 @@ describe('graphql - error handling in production', () => {
411398 }
412399 }
413400 ]
414- const response = await POST ( '/graphql' , { query } )
401+ const response = await POST ( '/graphql' , { query } , { headers : { 'Accept-Language' : 'en' } } )
415402 expect ( response . data ) . toMatchObject ( { errors } )
416403 expect ( response . data . errors [ 0 ] . extensions ) . not . toHaveProperty ( 'stacktrace' ) // No stacktrace in production
417404 } )
@@ -438,34 +425,7 @@ describe('graphql - error handling in production', () => {
438425 }
439426 }
440427 ]
441- const response = await POST ( '/graphql' , { query } )
442- expect ( response . data ) . toMatchObject ( { errors } )
443- expect ( response . data . errors [ 0 ] . extensions ) . not . toHaveProperty ( 'stacktrace' ) // No stacktrace in production
444- } )
445-
446- test ( 'req.reject with custom code' , async ( ) => {
447- const query = gql `
448- mutation {
449- CustomHandlerErrorsService {
450- Orders {
451- create(input: { id: 3, quantity: 20, stock: 10 }) {
452- id
453- quantity
454- stock
455- }
456- }
457- }
458- }
459- `
460- const errors = [
461- {
462- message : 'Internal Server Error' ,
463- extensions : {
464- code : '500'
465- }
466- }
467- ]
468- const response = await POST ( '/graphql' , { query } )
428+ const response = await POST ( '/graphql' , { query } , { headers : { 'Accept-Language' : 'en' } } )
469429 expect ( response . data ) . toMatchObject ( { errors } )
470430 expect ( response . data . errors [ 0 ] . extensions ) . not . toHaveProperty ( 'stacktrace' ) // No stacktrace in production
471431 } )
0 commit comments