UNPKG

2.27 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, '__esModule', { value: true });
4
5var tslib = require('tslib');
6require('../utilities/globals');
7var utilities = require('../utilities');
8
9var PROTOCOL_ERRORS_SYMBOL = Symbol();
10function graphQLResultHasProtocolErrors(result) {
11 if (result.extensions) {
12 return Array.isArray(result.extensions[PROTOCOL_ERRORS_SYMBOL]);
13 }
14 return false;
15}
16function isApolloError(err) {
17 return err.hasOwnProperty("graphQLErrors");
18}
19var generateErrorMessage = function (err) {
20 var errors = tslib.__spreadArray(tslib.__spreadArray(tslib.__spreadArray([], err.graphQLErrors, true), err.clientErrors, true), err.protocolErrors, true);
21 if (err.networkError)
22 errors.push(err.networkError);
23 return (errors
24 .map(function (err) {
25 return (utilities.isNonNullObject(err) && err.message) || "Error message not found.";
26 })
27 .join("\n"));
28};
29var ApolloError = (function (_super) {
30 tslib.__extends(ApolloError, _super);
31 function ApolloError(_a) {
32 var graphQLErrors = _a.graphQLErrors, protocolErrors = _a.protocolErrors, clientErrors = _a.clientErrors, networkError = _a.networkError, errorMessage = _a.errorMessage, extraInfo = _a.extraInfo;
33 var _this = _super.call(this, errorMessage) || this;
34 _this.name = "ApolloError";
35 _this.graphQLErrors = graphQLErrors || [];
36 _this.protocolErrors = protocolErrors || [];
37 _this.clientErrors = clientErrors || [];
38 _this.networkError = networkError || null;
39 _this.message = errorMessage || generateErrorMessage(_this);
40 _this.extraInfo = extraInfo;
41 _this.cause =
42 tslib.__spreadArray(tslib.__spreadArray(tslib.__spreadArray([
43 networkError
44 ], (graphQLErrors || []), true), (protocolErrors || []), true), (clientErrors || []), true).find(function (e) { return !!e; }) || null;
45 _this.__proto__ = ApolloError.prototype;
46 return _this;
47 }
48 return ApolloError;
49}(Error));
50
51exports.ApolloError = ApolloError;
52exports.PROTOCOL_ERRORS_SYMBOL = PROTOCOL_ERRORS_SYMBOL;
53exports.graphQLResultHasProtocolErrors = graphQLResultHasProtocolErrors;
54exports.isApolloError = isApolloError;
55//# sourceMappingURL=errors.cjs.map