locatedError.mjs 1003 B

1234567891011121314151617181920
  1. import inspect from "../jsutils/inspect.mjs";
  2. import { GraphQLError } from "./GraphQLError.mjs";
  3. /**
  4. * Given an arbitrary value, presumably thrown while attempting to execute a
  5. * GraphQL operation, produce a new GraphQLError aware of the location in the
  6. * document responsible for the original Error.
  7. */
  8. export function locatedError(rawOriginalError, nodes, path) {
  9. var _nodes;
  10. // Sometimes a non-error is thrown, wrap it as an Error instance to ensure a consistent Error interface.
  11. var originalError = rawOriginalError instanceof Error ? rawOriginalError : new Error('Unexpected error value: ' + inspect(rawOriginalError)); // Note: this uses a brand-check to support GraphQL errors originating from other contexts.
  12. if (Array.isArray(originalError.path)) {
  13. return originalError;
  14. }
  15. return new GraphQLError(originalError.message, (_nodes = originalError.nodes) !== null && _nodes !== void 0 ? _nodes : nodes, originalError.source, originalError.positions, path, originalError);
  16. }