Skip to content

Commit

Permalink
Rename ctorData to ctorConfig
Browse files Browse the repository at this point in the history
Summary:

Previously, ctorData is accessing all the attributes listed in ErrorConfig so it should be define as ErrorConfig instance and renamed as ctorConfig.

The common use case will bind the first 2 arguments of ApolloError.constructor() to name and a common configuration object, leaving the ctorConfig to provide the final customization.

We make sure that ctorConfig take precedence over config and merge them whenever necessary.
  • Loading branch information
lxcid committed Mar 28, 2018
1 parent d57470d commit b7fdcd9
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,17 @@ export class ApolloError extends ExtendableError {
// NOTE: The object passed to the Constructor is actually `ctorData`.
// We are binding the constructor to the name and config object
// for the first two parameters inside of `createError`
constructor(name: string, config: ErrorConfig, ctorData: any) {
super((ctorData && ctorData.message) || '');

const t = (ctorData && ctorData.time_thrown) || (new Date()).toISOString();
const m = (ctorData && ctorData.message) || '';
const configData = (ctorData && ctorData.data) || {};
const d = { ...this.data, ...configData };
const opts = ((ctorData && ctorData.options) || {});
constructor(name: string, config: ErrorConfig, ctorConfig: ErrorConfig) {
super((ctorConfig && ctorConfig.message) || (config && config.message) || '');

const t = (ctorConfig && ctorConfig.time_thrown) || (config && config.time_thrown) || (new Date()).toISOString();
const m = (ctorConfig && ctorConfig.message) || (config && config.message) || '';
const ctorData = (ctorConfig && ctorConfig.data) || {};
const configData = (config && config.data) || {};
const d = { ...this.data, ...configData, ...ctorData };
const ctorOptions = (ctorConfig && ctorConfig.options) || {};
const configOptions = (config && config.options) || {};
const opts = { ...configOptions, ...ctorOptions };


this.name = name;
Expand Down

0 comments on commit b7fdcd9

Please sign in to comment.