Skip to content

Commit d57470d

Browse files
committed
updated code with a couple of comments and made ctorData more explicit
1 parent 410cd17 commit d57470d

File tree

4 files changed

+21
-15
lines changed

4 files changed

+21
-15
lines changed

dist/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export declare class ApolloError extends ExtendableError {
2525
locations: any;
2626
_showLocations: boolean;
2727
_showPath: boolean;
28-
constructor(name: string, config: ErrorConfig);
28+
constructor(name: string, config: ErrorConfig, ctorData: any);
2929
serialize(): ErrorInfo;
3030
}
3131
export declare const isInstance: (e: any) => boolean;

dist/index.js

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,17 @@ export class ApolloError extends ExtendableError {
3333
_showLocations: boolean = false;
3434
_showPath: boolean = false;
3535

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) || {};
4245
const d = { ...this.data, ...configData };
43-
const opts = ((arguments[2] && arguments[2].options) || {});
46+
const opts = ((ctorData && ctorData.options) || {});
4447

4548

4649
this.name = name;
@@ -80,6 +83,9 @@ export const isInstance = e => e instanceof ApolloError;
8083
export const createError = (name: string, config: ErrorConfig) => {
8184
assert(isObject(config), 'createError requires a config object as the second parameter');
8285
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.
8389
return ApolloError.bind(null, name, config);
8490
};
8591

0 commit comments

Comments
 (0)