Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
thebigredgeek committed Feb 23, 2018
1 parent 6f4ffdc commit 0c4a6e1
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 13 deletions.
9 changes: 5 additions & 4 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ export interface ErrorInfo {
message: string;
name: string;
time_thrown: string;
data: string;
path: string;
locations: string;
data?: {};
path?: string;
locations?: any;
}
export declare class ApolloError extends ExtendableError {
name: string;
Expand All @@ -24,9 +24,10 @@ export declare class ApolloError extends ExtendableError {
path: any;
locations: any;
_showLocations: boolean;
_showPath: boolean;
constructor(name: string, config: ErrorConfig);
serialize(): ErrorInfo;
}
export declare const isInstance: (e: any) => boolean;
export declare const createError: (name: string, config: ErrorConfig) => ApolloError;
export declare const createError: (name: string, config: ErrorConfig) => any;
export declare const formatError: (error: any, returnNull?: boolean) => ErrorInfo;
14 changes: 10 additions & 4 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 12 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export class ApolloError extends ExtendableError {
path: any;
locations: any;
_showLocations: boolean = false;
_showPath: boolean = false;

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

serialize(): ErrorInfo {
const { name, message, time_thrown, data, _showLocations, path, locations } = this;
const { name, message, time_thrown, data, _showLocations, _showPath, path, locations } = this;

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

if (_showLocations) {
error.locations = locations;
}

if (_showPath) {
error.path = path;
}

Expand All @@ -74,7 +79,7 @@ export const isInstance = e => e instanceof ApolloError;
export const createError = (name: string, config: ErrorConfig) => {
assert(isObject(config), 'createError requires a config object as the second parameter');
assert(isString(config.message), 'createError requires a "message" property on the config object passed as the second parameter');
return new ApolloError(name, config);
return ApolloError.bind(null, name, config);
};

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

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

const { time_thrown, message, data, _showLocations } = originalError;
const { time_thrown, message, data, _showLocations, _showPath } = originalError;
const { locations, path } = error;

if (_showLocations) {
const { locations, path } = error;
originalError.locations = locations;
}

if (_showPath) {
originalError.path = path;
}

Expand Down

0 comments on commit 0c4a6e1

Please sign in to comment.