Skip to content

Commit 0c4a6e1

Browse files
committed
fixes
1 parent 6f4ffdc commit 0c4a6e1

File tree

4 files changed

+28
-13
lines changed

4 files changed

+28
-13
lines changed

dist/index.d.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ export interface ErrorInfo {
1212
message: string;
1313
name: string;
1414
time_thrown: string;
15-
data: string;
16-
path: string;
17-
locations: string;
15+
data?: {};
16+
path?: string;
17+
locations?: any;
1818
}
1919
export declare class ApolloError extends ExtendableError {
2020
name: string;
@@ -24,9 +24,10 @@ export declare class ApolloError extends ExtendableError {
2424
path: any;
2525
locations: any;
2626
_showLocations: boolean;
27+
_showPath: boolean;
2728
constructor(name: string, config: ErrorConfig);
2829
serialize(): ErrorInfo;
2930
}
3031
export declare const isInstance: (e: any) => boolean;
31-
export declare const createError: (name: string, config: ErrorConfig) => ApolloError;
32+
export declare const createError: (name: string, config: ErrorConfig) => any;
3233
export declare const formatError: (error: any, returnNull?: boolean) => ErrorInfo;

dist/index.js

+10-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.ts

+12-4
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export class ApolloError extends ExtendableError {
3131
path: any;
3232
locations: any;
3333
_showLocations: boolean = false;
34+
_showPath: boolean = false;
3435

3536
constructor(name: string, config: ErrorConfig) {
3637
super((arguments[2] && arguments[2].message) || '');
@@ -46,10 +47,11 @@ export class ApolloError extends ExtendableError {
4647
this.time_thrown = t;
4748
this.data = d;
4849
this._showLocations = !!opts.showLocations;
50+
this._showPath = !!opts.showPath;
4951
}
5052

5153
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;
5355

5456
let error: ErrorInfo = {
5557
message,
@@ -62,6 +64,9 @@ export class ApolloError extends ExtendableError {
6264

6365
if (_showLocations) {
6466
error.locations = locations;
67+
}
68+
69+
if (_showPath) {
6570
error.path = path;
6671
}
6772

@@ -74,7 +79,7 @@ export const isInstance = e => e instanceof ApolloError;
7479
export const createError = (name: string, config: ErrorConfig) => {
7580
assert(isObject(config), 'createError requires a config object as the second parameter');
7681
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);
7883
};
7984

8085
export const formatError = (error, returnNull = false): ErrorInfo => {
@@ -86,11 +91,14 @@ export const formatError = (error, returnNull = false): ErrorInfo => {
8691

8792
if (!name || !isInstance(originalError)) return returnNull ? null : error;
8893

89-
const { time_thrown, message, data, _showLocations } = originalError;
94+
const { time_thrown, message, data, _showLocations, _showPath } = originalError;
95+
const { locations, path } = error;
9096

9197
if (_showLocations) {
92-
const { locations, path } = error;
9398
originalError.locations = locations;
99+
}
100+
101+
if (_showPath) {
94102
originalError.path = path;
95103
}
96104

0 commit comments

Comments
 (0)