@@ -11,11 +11,14 @@ class ApolloError extends ExtendableError {
11
11
constructor ( name , {
12
12
message,
13
13
time_thrown = ( new Date ( ) ) . toISOString ( ) ,
14
- data = { }
14
+ data = { } ,
15
+ showLocations,
16
+ showPath,
15
17
} ) {
16
18
const t = ( arguments [ 2 ] && arguments [ 2 ] . thrown_at ) || time_thrown ;
17
19
const d = Object . assign ( { } , data , ( ( arguments [ 2 ] && arguments [ 2 ] . data ) || { } ) ) ;
18
-
20
+ const l = showLocations && ( arguments [ 2 ] && arguments [ 2 ] . locations ) ;
21
+ const p = showPath && ( arguments [ 2 ] && arguments [ 2 ] . path ) ;
19
22
super ( serializeName ( [
20
23
name ,
21
24
t ,
@@ -28,36 +31,45 @@ class ApolloError extends ExtendableError {
28
31
this . _humanized_message = message || '' ;
29
32
this . _time_thrown = t ;
30
33
this . _data = d ;
34
+ this . _locations = l ;
35
+ this . _path = p ;
31
36
}
32
37
serialize ( ) {
33
38
const name = this . _name ;
34
39
const message = this . _humanized_message ;
35
40
const time_thrown = this . _time_thrown ;
36
41
const data = this . _data ;
42
+ const locations = this . _locations ;
43
+ const path = this . _path ;
37
44
return {
38
45
message,
39
46
name,
40
47
time_thrown,
41
- data
48
+ data,
49
+ locations,
50
+ path,
42
51
} ;
43
52
}
44
53
}
45
54
46
- export const createError = ( name , data = { message : 'An error has occurred' } ) => {
55
+ export const createError = ( name , data = { message : 'An error has occurred' , showLocations , showPath } ) => {
47
56
const e = ApolloError . bind ( null , name , data ) ;
48
57
errorMap . set ( name , e ) ;
49
58
return e ;
50
59
} ;
51
60
52
61
export const formatError = ( originalError , returnNull = false ) => {
53
62
const [ name , thrown_at , d ] = deserializeName ( originalError . message ) ;
63
+ const { locations, path } = originalError ;
54
64
const data = d !== undefined ? JSON . parse ( d ) : { } ;
55
65
if ( ! name ) return returnNull ? null : originalError ;
56
66
const CustomError = errorMap . get ( name ) ;
57
67
if ( ! CustomError ) return returnNull ? null : originalError ;
58
68
const error = new CustomError ( {
59
69
thrown_at,
60
- data
70
+ data,
71
+ locations,
72
+ path,
61
73
} ) ;
62
74
return error . serialize ( ) ;
63
75
} ;
0 commit comments