formatError.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.formatError = formatError;
  6. var _devAssert = _interopRequireDefault(require("../jsutils/devAssert.js"));
  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. var _error$message;
  14. error || (0, _devAssert.default)(0, 'Received null or undefined error.');
  15. var message = (_error$message = error.message) !== null && _error$message !== void 0 ? _error$message : 'An unknown error occurred.';
  16. var locations = error.locations;
  17. var path = error.path;
  18. var extensions = error.extensions;
  19. return extensions ? {
  20. message: message,
  21. locations: locations,
  22. path: path,
  23. extensions: extensions
  24. } : {
  25. message: message,
  26. locations: locations,
  27. path: path
  28. };
  29. }
  30. /**
  31. * @see https://github.com/graphql/graphql-spec/blob/master/spec/Section%207%20--%20Response.md#errors
  32. */