@@ -31,6 +31,7 @@ export class ApolloError extends ExtendableError {
31
31
path : any ;
32
32
locations : any ;
33
33
_showLocations : boolean = false ;
34
+ _showPath : boolean = false ;
34
35
35
36
constructor ( name : string , config : ErrorConfig ) {
36
37
super ( ( arguments [ 2 ] && arguments [ 2 ] . message ) || '' ) ;
@@ -46,10 +47,11 @@ export class ApolloError extends ExtendableError {
46
47
this . time_thrown = t ;
47
48
this . data = d ;
48
49
this . _showLocations = ! ! opts . showLocations ;
50
+ this . _showPath = ! ! opts . showPath ;
49
51
}
50
52
51
53
serialize ( ) : ErrorInfo {
52
- const { name, message, time_thrown, data, _showLocations, path, locations } = this ;
54
+ const { name, message, time_thrown, data, _showLocations, _showPath , path, locations } = this ;
53
55
54
56
let error : ErrorInfo = {
55
57
message,
@@ -62,6 +64,9 @@ export class ApolloError extends ExtendableError {
62
64
63
65
if ( _showLocations ) {
64
66
error . locations = locations ;
67
+ }
68
+
69
+ if ( _showPath ) {
65
70
error . path = path ;
66
71
}
67
72
@@ -74,7 +79,7 @@ export const isInstance = e => e instanceof ApolloError;
74
79
export const createError = ( name : string , config : ErrorConfig ) => {
75
80
assert ( isObject ( config ) , 'createError requires a config object as the second parameter' ) ;
76
81
assert ( isString ( config . message ) , 'createError requires a "message" property on the config object passed as the second parameter' ) ;
77
- return new ApolloError ( name , config ) ;
82
+ return ApolloError . bind ( null , name , config ) ;
78
83
} ;
79
84
80
85
export const formatError = ( error , returnNull = false ) : ErrorInfo => {
@@ -86,11 +91,14 @@ export const formatError = (error, returnNull = false): ErrorInfo => {
86
91
87
92
if ( ! name || ! isInstance ( originalError ) ) return returnNull ? null : error ;
88
93
89
- const { time_thrown, message, data, _showLocations } = originalError ;
94
+ const { time_thrown, message, data, _showLocations, _showPath } = originalError ;
95
+ const { locations, path } = error ;
90
96
91
97
if ( _showLocations ) {
92
- const { locations, path } = error ;
93
98
originalError . locations = locations ;
99
+ }
100
+
101
+ if ( _showPath ) {
94
102
originalError . path = path ;
95
103
}
96
104
0 commit comments