Skip to content

Commit 3d27953

Browse files
committed
Include originalError in GraphQL error to preserve any additional info
Fixes #251
1 parent 786340e commit 3d27953

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/error/GraphQLError.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export class GraphQLError extends Error {
2020
source: Source;
2121
positions: Array<number>;
2222
locations: any;
23+
originalError: ?Error;
2324

2425
constructor(
2526
message: string,

src/error/locatedError.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,15 @@ import { GraphQLError } from './GraphQLError';
1616
* GraphQL operation, produce a new GraphQLError aware of the location in the
1717
* document responsible for the original Error.
1818
*/
19-
export function locatedError(error: ?Error, nodes: Array<any>): GraphQLError {
20-
var message = error ?
21-
error.message || String(error) :
19+
export function locatedError(
20+
originalError: ?Error,
21+
nodes: Array<any>
22+
): GraphQLError {
23+
const message = originalError ?
24+
originalError.message || String(originalError) :
2225
'An unknown error occurred.';
23-
var stack = error ? error.stack : null;
24-
return new GraphQLError(message, nodes, stack);
26+
const stack = originalError ? originalError.stack : null;
27+
const error = new GraphQLError(message, nodes, stack);
28+
error.originalError = originalError;
29+
return error;
2530
}

0 commit comments

Comments
 (0)