formatError.js 1006 B

1234567891011121314151617181920212223242526272829303132333435
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.formatError = formatError;
  6. var _devAssert = _interopRequireDefault(require("../jsutils/devAssert"));
  7. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  8. /**
  9. * Given a GraphQLError, format it according to the rules described by the
  10. * Response Format, Errors section of the GraphQL Specification.
  11. */
  12. function formatError(error) {
  13. error || (0, _devAssert.default)(0, 'Received null or undefined error.');
  14. var message = error.message || 'An unknown error occurred.';
  15. var locations = error.locations;
  16. var path = error.path;
  17. var extensions = error.extensions;
  18. return extensions ? {
  19. message: message,
  20. locations: locations,
  21. path: path,
  22. extensions: extensions
  23. } : {
  24. message: message,
  25. locations: locations,
  26. path: path
  27. };
  28. }
  29. /**
  30. * @see https://github.com/graphql/graphql-spec/blob/master/spec/Section%207%20--%20Response.md#errors
  31. */