formatError.mjs 758 B

1234567891011121314151617181920212223242526
  1. import devAssert from '../jsutils/devAssert';
  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. error || devAssert(0, 'Received null or undefined error.');
  8. var message = error.message || 'An unknown error occurred.';
  9. var locations = error.locations;
  10. var path = error.path;
  11. var extensions = error.extensions;
  12. return extensions ? {
  13. message: message,
  14. locations: locations,
  15. path: path,
  16. extensions: extensions
  17. } : {
  18. message: message,
  19. locations: locations,
  20. path: path
  21. };
  22. }
  23. /**
  24. * @see https://github.com/graphql/graphql-spec/blob/master/spec/Section%207%20--%20Response.md#errors
  25. */