UNPKG

1.27 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.locatedError = locatedError;
7
8var _inspect = _interopRequireDefault(require("../jsutils/inspect.js"));
9
10var _GraphQLError = require("./GraphQLError.js");
11
12function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
14/**
15 * Given an arbitrary value, presumably thrown while attempting to execute a
16 * GraphQL operation, produce a new GraphQLError aware of the location in the
17 * document responsible for the original Error.
18 */
19function locatedError(rawOriginalError, nodes, path) {
20 var _nodes;
21
22 // Sometimes a non-error is thrown, wrap it as an Error instance to ensure a consistent Error interface.
23 var originalError = rawOriginalError instanceof Error ? rawOriginalError : new Error('Unexpected error value: ' + (0, _inspect.default)(rawOriginalError)); // Note: this uses a brand-check to support GraphQL errors originating from other contexts.
24
25 if (Array.isArray(originalError.path)) {
26 return originalError;
27 }
28
29 return new _GraphQLError.GraphQLError(originalError.message, (_nodes = originalError.nodes) !== null && _nodes !== void 0 ? _nodes : nodes, originalError.source, originalError.positions, path, originalError);
30}