Skip to content

Commit a710b53

Browse files
committed
Ensure internalData property is actually present on the error instance
1 parent 94b3502 commit a710b53

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/index.ts

+5
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export class ApolloError extends ExtendableError {
2929
message: string;
3030
time_thrown: string;
3131
data: object;
32+
internalData: object;
3233
path: any;
3334
locations: any;
3435
_showLocations: boolean = false;
@@ -43,8 +44,11 @@ export class ApolloError extends ExtendableError {
4344
const t = (ctorConfig && ctorConfig.time_thrown) || (config && config.time_thrown) || (new Date()).toISOString();
4445
const m = (ctorConfig && ctorConfig.message) || (config && config.message) || '';
4546
const ctorData = (ctorConfig && ctorConfig.data) || {};
47+
const ctorInternalData = (ctorConfig && ctorConfig.internalData) || {}
4648
const configData = (config && config.data) || {};
49+
const configInternalData = (config && config.internalData) || {}
4750
const d = { ...this.data, ...configData, ...ctorData };
51+
const id = { ...this.internalData, ...configInternalData, ...ctorInternalData}
4852
const ctorOptions = (ctorConfig && ctorConfig.options) || {};
4953
const configOptions = (config && config.options) || {};
5054
const opts = { ...configOptions, ...ctorOptions };
@@ -54,6 +58,7 @@ export class ApolloError extends ExtendableError {
5458
this.message = m;
5559
this.time_thrown = t;
5660
this.data = d;
61+
this.internalData = id;
5762
this._showLocations = !!opts.showLocations;
5863
this._showPath = !!opts.showPath;
5964
}

test/spec.js

+3
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@ describe('formatError', () => {
147147
});
148148

149149
const e = new FooError();
150+
expect(e.internalData).to.to.eql({
151+
secret: 'SQL ERROR'
152+
})
150153
const s = formatError(e);
151154
expect(s.internalData).to.eq(undefined)
152155
})

0 commit comments

Comments
 (0)