UNPKG

758 BJavaScriptView Raw
1import devAssert from '../jsutils/devAssert';
2
3/**
4 * Given a GraphQLError, format it according to the rules described by the
5 * Response Format, Errors section of the GraphQL Specification.
6 */
7export function formatError(error) {
8 error || devAssert(0, 'Received null or undefined error.');
9 var message = 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 */