locatedError.js 1.2 KB

123456789101112131415161718192021222324252627282930
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.locatedError = locatedError;
  6. var _inspect = _interopRequireDefault(require("../jsutils/inspect.js"));
  7. var _GraphQLError = require("./GraphQLError.js");
  8. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  9. /**
  10. * Given an arbitrary value, presumably thrown while attempting to execute a
  11. * GraphQL operation, produce a new GraphQLError aware of the location in the
  12. * document responsible for the original Error.
  13. */
  14. function locatedError(rawOriginalError, nodes, path) {
  15. var _nodes;
  16. // Sometimes a non-error is thrown, wrap it as an Error instance to ensure a consistent Error interface.
  17. 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.
  18. if (Array.isArray(originalError.path)) {
  19. return originalError;
  20. }
  21. return new _GraphQLError.GraphQLError(originalError.message, (_nodes = originalError.nodes) !== null && _nodes !== void 0 ? _nodes : nodes, originalError.source, originalError.positions, path, originalError);
  22. }