UNPKG

5.59 kBJavaScriptView Raw
1(function (global, factory) {
2 typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('apollo-link')) :
3 typeof define === 'function' && define.amd ? define(['exports', 'apollo-link'], factory) :
4 (global = global || self, factory((global.apolloLink = global.apolloLink || {}, global.apolloLink.error = {}), global.apolloLink.core));
5}(this, function (exports, apolloLink) { 'use strict';
6
7 /*! *****************************************************************************
8 Copyright (c) Microsoft Corporation. All rights reserved.
9 Licensed under the Apache License, Version 2.0 (the "License"); you may not use
10 this file except in compliance with the License. You may obtain a copy of the
11 License at http://www.apache.org/licenses/LICENSE-2.0
12
13 THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
15 WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
16 MERCHANTABLITY OR NON-INFRINGEMENT.
17
18 See the Apache Version 2.0 License for specific language governing permissions
19 and limitations under the License.
20 ***************************************************************************** */
21 /* global Reflect, Promise */
22
23 var extendStatics = function(d, b) {
24 extendStatics = Object.setPrototypeOf ||
25 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
26 function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
27 return extendStatics(d, b);
28 };
29
30 function __extends(d, b) {
31 extendStatics(d, b);
32 function __() { this.constructor = d; }
33 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
34 }
35
36 var onError = function (errorHandler) {
37 return new apolloLink.ApolloLink(function (operation, forward) {
38 return new apolloLink.Observable(function (observer) {
39 var sub;
40 var retriedSub;
41 var retriedResult;
42 try {
43 sub = forward(operation).subscribe({
44 next: function (result) {
45 if (result.errors) {
46 retriedResult = errorHandler({
47 graphQLErrors: result.errors,
48 response: result,
49 operation: operation,
50 forward: forward,
51 });
52 if (retriedResult) {
53 retriedSub = retriedResult.subscribe({
54 next: observer.next.bind(observer),
55 error: observer.error.bind(observer),
56 complete: observer.complete.bind(observer),
57 });
58 return;
59 }
60 }
61 observer.next(result);
62 },
63 error: function (networkError) {
64 retriedResult = errorHandler({
65 operation: operation,
66 networkError: networkError,
67 graphQLErrors: networkError.result && networkError.result.errors,
68 forward: forward,
69 });
70 if (retriedResult) {
71 retriedSub = retriedResult.subscribe({
72 next: observer.next.bind(observer),
73 error: observer.error.bind(observer),
74 complete: observer.complete.bind(observer),
75 });
76 return;
77 }
78 observer.error(networkError);
79 },
80 complete: function () {
81 if (!retriedResult) {
82 observer.complete.bind(observer)();
83 }
84 },
85 });
86 }
87 catch (e) {
88 errorHandler({ networkError: e, operation: operation, forward: forward });
89 observer.error(e);
90 }
91 return function () {
92 if (sub)
93 sub.unsubscribe();
94 if (retriedSub)
95 sub.unsubscribe();
96 };
97 });
98 });
99 };
100 var ErrorLink = (function (_super) {
101 __extends(ErrorLink, _super);
102 function ErrorLink(errorHandler) {
103 var _this = _super.call(this) || this;
104 _this.link = onError(errorHandler);
105 return _this;
106 }
107 ErrorLink.prototype.request = function (operation, forward) {
108 return this.link.request(operation, forward);
109 };
110 return ErrorLink;
111 }(apolloLink.ApolloLink));
112
113 exports.onError = onError;
114 exports.ErrorLink = ErrorLink;
115
116 Object.defineProperty(exports, '__esModule', { value: true });
117
118}));
119//# sourceMappingURL=bundle.umd.js.map