@@ -33,14 +33,17 @@ export class ApolloError extends ExtendableError {
33
33
_showLocations : boolean = false ;
34
34
_showPath : boolean = false ;
35
35
36
- constructor ( name : string , config : ErrorConfig ) {
37
- super ( ( arguments [ 2 ] && arguments [ 2 ] . message ) || '' ) ;
38
-
39
- const t = ( arguments [ 2 ] && arguments [ 2 ] . time_thrown ) || ( new Date ( ) ) . toISOString ( ) ;
40
- const m = ( arguments [ 2 ] && arguments [ 2 ] . message ) || '' ;
41
- const configData = ( arguments [ 2 ] && arguments [ 2 ] . data ) || { } ;
36
+ // NOTE: The object passed to the Constructor is actually `ctorData`.
37
+ // We are binding the constructor to the name and config object
38
+ // for the first two parameters inside of `createError`
39
+ constructor ( name : string , config : ErrorConfig , ctorData : any ) {
40
+ super ( ( ctorData && ctorData . message ) || '' ) ;
41
+
42
+ const t = ( ctorData && ctorData . time_thrown ) || ( new Date ( ) ) . toISOString ( ) ;
43
+ const m = ( ctorData && ctorData . message ) || '' ;
44
+ const configData = ( ctorData && ctorData . data ) || { } ;
42
45
const d = { ...this . data , ...configData } ;
43
- const opts = ( ( arguments [ 2 ] && arguments [ 2 ] . options ) || { } ) ;
46
+ const opts = ( ( ctorData && ctorData . options ) || { } ) ;
44
47
45
48
46
49
this . name = name ;
@@ -80,6 +83,9 @@ export const isInstance = e => e instanceof ApolloError;
80
83
export const createError = ( name : string , config : ErrorConfig ) => {
81
84
assert ( isObject ( config ) , 'createError requires a config object as the second parameter' ) ;
82
85
assert ( isString ( config . message ) , 'createError requires a "message" property on the config object passed as the second parameter' ) ;
86
+ // NOTE: The first two parameters give to the constructor will always be name and config
87
+ // Parameters passed to the constructor when `new` is invoked will be passed as
88
+ // subsequent parameters.
83
89
return ApolloError . bind ( null , name , config ) ;
84
90
} ;
85
91
0 commit comments