@@ -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;
7479export 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
8085export 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