formatError.mjs 858 B

12345678910111213141516171819202122232425262728
  1. import devAssert from "../jsutils/devAssert.mjs";
  2. /**
  3. * Given a GraphQLError, format it according to the rules described by the
  4. * Response Format, Errors section of the GraphQL Specification.
  5. */
  6. export function formatError(error) {
  7. var _error$message;
  8. error || devAssert(0, 'Received null or undefined error.');
  9. var message = (_error$message = error.message) !== null && _error$message !== void 0 ? _error$message : 'An unknown error occurred.';
  10. var locations = error.locations;
  11. var path = error.path;
  12. var extensions = error.extensions;
  13. return extensions ? {
  14. message: message,
  15. locations: locations,
  16. path: path,
  17. extensions: extensions
  18. } : {
  19. message: message,
  20. locations: locations,
  21. path: path
  22. };
  23. }
  24. /**
  25. * @see https://github.com/graphql/graphql-spec/blob/master/spec/Section%207%20--%20Response.md#errors
  26. */