1 | import { __extends, __spreadArray } from "tslib";
|
2 | import "../utilities/globals/index.js";
|
3 | import { isNonNullObject } from "../utilities/index.js";
|
4 |
|
5 |
|
6 |
|
7 | export var PROTOCOL_ERRORS_SYMBOL = Symbol();
|
8 | export function graphQLResultHasProtocolErrors(result) {
|
9 | if (result.extensions) {
|
10 | return Array.isArray(result.extensions[PROTOCOL_ERRORS_SYMBOL]);
|
11 | }
|
12 | return false;
|
13 | }
|
14 | export function isApolloError(err) {
|
15 | return err.hasOwnProperty("graphQLErrors");
|
16 | }
|
17 |
|
18 |
|
19 |
|
20 |
|
21 | var generateErrorMessage = function (err) {
|
22 | var errors = __spreadArray(__spreadArray(__spreadArray([], err.graphQLErrors, true), err.clientErrors, true), err.protocolErrors, true);
|
23 | if (err.networkError)
|
24 | errors.push(err.networkError);
|
25 | return (errors
|
26 |
|
27 | .map(function (err) {
|
28 | return (isNonNullObject(err) && err.message) || "Error message not found.";
|
29 | })
|
30 | .join("\n"));
|
31 | };
|
32 | var ApolloError = (function (_super) {
|
33 | __extends(ApolloError, _super);
|
34 |
|
35 |
|
36 |
|
37 |
|
38 | function ApolloError(_a) {
|
39 | var graphQLErrors = _a.graphQLErrors, protocolErrors = _a.protocolErrors, clientErrors = _a.clientErrors, networkError = _a.networkError, errorMessage = _a.errorMessage, extraInfo = _a.extraInfo;
|
40 | var _this = _super.call(this, errorMessage) || this;
|
41 | _this.name = "ApolloError";
|
42 | _this.graphQLErrors = graphQLErrors || [];
|
43 | _this.protocolErrors = protocolErrors || [];
|
44 | _this.clientErrors = clientErrors || [];
|
45 | _this.networkError = networkError || null;
|
46 | _this.message = errorMessage || generateErrorMessage(_this);
|
47 | _this.extraInfo = extraInfo;
|
48 | _this.cause =
|
49 | __spreadArray(__spreadArray(__spreadArray([
|
50 | networkError
|
51 | ], (graphQLErrors || []), true), (protocolErrors || []), true), (clientErrors || []), true).find(function (e) { return !!e; }) || null;
|
52 |
|
53 |
|
54 | _this.__proto__ = ApolloError.prototype;
|
55 | return _this;
|
56 | }
|
57 | return ApolloError;
|
58 | }(Error));
|
59 | export { ApolloError };
|
60 |
|
\ | No newline at end of file |