-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathGraphQLAggregateError.mjs
70 lines (59 loc) · 2.02 KB
/
GraphQLAggregateError.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// @ts-check
import { GraphQLError } from "graphql";
/**
* An aggregate error for GraphQL schema validation, query validation, or
* execution errors.
*/
export default class GraphQLAggregateError
// Todo: Use `AggregateError` instead of `Error`, once it’s available in all
// supported Node.js versions.
extends Error
{
/**
* @param {ReadonlyArray<import("graphql").GraphQLError>} errors GraphQL
* errors.
* @param {string} message Aggregate error message.
* @param {number} status Determines the response HTTP status code.
* @param {boolean} expose Should the original error {@linkcode message} be
* exposed to the client. Note that individual {@linkcode errors} that
* represent GraphQL execution errors thrown in resolvers have an
* {@linkcode GraphQLError.originalError originalError} property that may
* have an `expose` property.
*/
constructor(errors, message, status, expose) {
if (!Array.isArray(errors))
throw new TypeError("Argument 1 `errors` must be an array.");
if (!errors.every((error) => error instanceof GraphQLError))
throw new TypeError(
"Argument 1 `errors` must be an array containing only `GraphQLError` instances."
);
if (typeof message !== "string")
throw new TypeError("Argument 2 `message` must be a string.");
if (typeof status !== "number")
throw new TypeError("Argument 3 `status` must be a number.");
if (typeof expose !== "boolean")
throw new TypeError("Argument 4 `expose` must be a boolean.");
super(message);
/**
* Error name.
* @type {string}
*/
this.name = "GraphQLAggregateError";
/**
* GraphQL errors.
* @type {Array<GraphQLError>}
*/
this.errors = [...errors];
/**
* Determines the response HTTP status code.
* @type {number}
*/
this.status = status;
/**
* Should the {@linkcode GraphQLAggregateError.message message} be exposed
* to the client.
* @type {boolean}
*/
this.expose = expose;
}
}