···
1
+
import { getLocation } from 'graphql/language/location';
2
+
import { printLocation, printSourceLocation } from 'graphql/language/printLocation';
4
+
export class GraphQLError extends Error {
16
+
this.name = 'GraphQLError';
17
+
this.message = message;
19
+
if (path) this.path = path;
20
+
if (nodes) this.nodes = nodes;
21
+
if (source) this.source = source;
22
+
if (positions) this.positions = positions;
23
+
if (originalError) this.originalError = originalError;
25
+
let _extensions = extensions;
26
+
if (_extensions == null && originalError != null) {
27
+
const originalExtensions = originalError.extensions;
28
+
if (isObjectLike(originalExtensions)) {
29
+
_extensions = originalExtensions;
34
+
this.extensions = _extensions;
39
+
return printError(this);
44
+
* Prints a GraphQLError to a string, representing useful location information
45
+
* about the error's position in the source.
47
+
export function printError(error) {
48
+
let output = error.message;
51
+
for (const node of error.nodes) {
53
+
output += '\n\n' + printLocation(node.loc);
56
+
} else if (error.source && error.locations) {
57
+
for (const location of error.locations) {
58
+
output += '\n\n' + printSourceLocation(error.source, location);