uniapp-request-sdk 1.4.12 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1067 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.esm.js +435 -70
- package/dist/index.umd.js +435 -70
- package/package.json +2 -1
package/dist/index.d.ts
CHANGED
|
@@ -7,6 +7,8 @@ interface IParams {
|
|
|
7
7
|
onErrorHandler?: (error: any) => void;
|
|
8
8
|
/** 公共请求头 */
|
|
9
9
|
header?: Record<string, string>;
|
|
10
|
+
/** 请求头预处理函数,用于动态获取或修改请求头,在token设置后执行 */
|
|
11
|
+
headerProcessor?: (header: Record<string, string>) => Promise<Record<string, string>> | Record<string, string>;
|
|
10
12
|
/** 请求尝试次数,默认3次 */
|
|
11
13
|
maxRetryCount?: number;
|
|
12
14
|
/** 请求超时时间默认10s,ms为单位 */
|
|
@@ -40,6 +42,8 @@ declare class UniRequest {
|
|
|
40
42
|
private onErrorHandler;
|
|
41
43
|
/** 默认请求头 */
|
|
42
44
|
private header?;
|
|
45
|
+
/** 请求头预处理函数 */
|
|
46
|
+
private headerProcessor?;
|
|
43
47
|
private maxRetryCount;
|
|
44
48
|
/** 超时时间 */
|
|
45
49
|
private timeout;
|
package/dist/index.esm.js
CHANGED
|
@@ -1,3 +1,334 @@
|
|
|
1
|
+
function _regeneratorRuntime() {
|
|
2
|
+
_regeneratorRuntime = function () {
|
|
3
|
+
return exports;
|
|
4
|
+
};
|
|
5
|
+
var exports = {},
|
|
6
|
+
Op = Object.prototype,
|
|
7
|
+
hasOwn = Op.hasOwnProperty,
|
|
8
|
+
defineProperty = Object.defineProperty || function (obj, key, desc) {
|
|
9
|
+
obj[key] = desc.value;
|
|
10
|
+
},
|
|
11
|
+
$Symbol = "function" == typeof Symbol ? Symbol : {},
|
|
12
|
+
iteratorSymbol = $Symbol.iterator || "@@iterator",
|
|
13
|
+
asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator",
|
|
14
|
+
toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
|
|
15
|
+
function define(obj, key, value) {
|
|
16
|
+
return Object.defineProperty(obj, key, {
|
|
17
|
+
value: value,
|
|
18
|
+
enumerable: !0,
|
|
19
|
+
configurable: !0,
|
|
20
|
+
writable: !0
|
|
21
|
+
}), obj[key];
|
|
22
|
+
}
|
|
23
|
+
try {
|
|
24
|
+
define({}, "");
|
|
25
|
+
} catch (err) {
|
|
26
|
+
define = function (obj, key, value) {
|
|
27
|
+
return obj[key] = value;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function wrap(innerFn, outerFn, self, tryLocsList) {
|
|
31
|
+
var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator,
|
|
32
|
+
generator = Object.create(protoGenerator.prototype),
|
|
33
|
+
context = new Context(tryLocsList || []);
|
|
34
|
+
return defineProperty(generator, "_invoke", {
|
|
35
|
+
value: makeInvokeMethod(innerFn, self, context)
|
|
36
|
+
}), generator;
|
|
37
|
+
}
|
|
38
|
+
function tryCatch(fn, obj, arg) {
|
|
39
|
+
try {
|
|
40
|
+
return {
|
|
41
|
+
type: "normal",
|
|
42
|
+
arg: fn.call(obj, arg)
|
|
43
|
+
};
|
|
44
|
+
} catch (err) {
|
|
45
|
+
return {
|
|
46
|
+
type: "throw",
|
|
47
|
+
arg: err
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.wrap = wrap;
|
|
52
|
+
var ContinueSentinel = {};
|
|
53
|
+
function Generator() {}
|
|
54
|
+
function GeneratorFunction() {}
|
|
55
|
+
function GeneratorFunctionPrototype() {}
|
|
56
|
+
var IteratorPrototype = {};
|
|
57
|
+
define(IteratorPrototype, iteratorSymbol, function () {
|
|
58
|
+
return this;
|
|
59
|
+
});
|
|
60
|
+
var getProto = Object.getPrototypeOf,
|
|
61
|
+
NativeIteratorPrototype = getProto && getProto(getProto(values([])));
|
|
62
|
+
NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype);
|
|
63
|
+
var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
|
|
64
|
+
function defineIteratorMethods(prototype) {
|
|
65
|
+
["next", "throw", "return"].forEach(function (method) {
|
|
66
|
+
define(prototype, method, function (arg) {
|
|
67
|
+
return this._invoke(method, arg);
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
function AsyncIterator(generator, PromiseImpl) {
|
|
72
|
+
function invoke(method, arg, resolve, reject) {
|
|
73
|
+
var record = tryCatch(generator[method], generator, arg);
|
|
74
|
+
if ("throw" !== record.type) {
|
|
75
|
+
var result = record.arg,
|
|
76
|
+
value = result.value;
|
|
77
|
+
return value && "object" == typeof value && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
|
|
78
|
+
invoke("next", value, resolve, reject);
|
|
79
|
+
}, function (err) {
|
|
80
|
+
invoke("throw", err, resolve, reject);
|
|
81
|
+
}) : PromiseImpl.resolve(value).then(function (unwrapped) {
|
|
82
|
+
result.value = unwrapped, resolve(result);
|
|
83
|
+
}, function (error) {
|
|
84
|
+
return invoke("throw", error, resolve, reject);
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
reject(record.arg);
|
|
88
|
+
}
|
|
89
|
+
var previousPromise;
|
|
90
|
+
defineProperty(this, "_invoke", {
|
|
91
|
+
value: function (method, arg) {
|
|
92
|
+
function callInvokeWithMethodAndArg() {
|
|
93
|
+
return new PromiseImpl(function (resolve, reject) {
|
|
94
|
+
invoke(method, arg, resolve, reject);
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
function makeInvokeMethod(innerFn, self, context) {
|
|
102
|
+
var state = "suspendedStart";
|
|
103
|
+
return function (method, arg) {
|
|
104
|
+
if ("executing" === state) throw new Error("Generator is already running");
|
|
105
|
+
if ("completed" === state) {
|
|
106
|
+
if ("throw" === method) throw arg;
|
|
107
|
+
return doneResult();
|
|
108
|
+
}
|
|
109
|
+
for (context.method = method, context.arg = arg;;) {
|
|
110
|
+
var delegate = context.delegate;
|
|
111
|
+
if (delegate) {
|
|
112
|
+
var delegateResult = maybeInvokeDelegate(delegate, context);
|
|
113
|
+
if (delegateResult) {
|
|
114
|
+
if (delegateResult === ContinueSentinel) continue;
|
|
115
|
+
return delegateResult;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) {
|
|
119
|
+
if ("suspendedStart" === state) throw state = "completed", context.arg;
|
|
120
|
+
context.dispatchException(context.arg);
|
|
121
|
+
} else "return" === context.method && context.abrupt("return", context.arg);
|
|
122
|
+
state = "executing";
|
|
123
|
+
var record = tryCatch(innerFn, self, context);
|
|
124
|
+
if ("normal" === record.type) {
|
|
125
|
+
if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue;
|
|
126
|
+
return {
|
|
127
|
+
value: record.arg,
|
|
128
|
+
done: context.done
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
"throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg);
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
function maybeInvokeDelegate(delegate, context) {
|
|
136
|
+
var methodName = context.method,
|
|
137
|
+
method = delegate.iterator[methodName];
|
|
138
|
+
if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel;
|
|
139
|
+
var record = tryCatch(method, delegate.iterator, context.arg);
|
|
140
|
+
if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel;
|
|
141
|
+
var info = record.arg;
|
|
142
|
+
return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel);
|
|
143
|
+
}
|
|
144
|
+
function pushTryEntry(locs) {
|
|
145
|
+
var entry = {
|
|
146
|
+
tryLoc: locs[0]
|
|
147
|
+
};
|
|
148
|
+
1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry);
|
|
149
|
+
}
|
|
150
|
+
function resetTryEntry(entry) {
|
|
151
|
+
var record = entry.completion || {};
|
|
152
|
+
record.type = "normal", delete record.arg, entry.completion = record;
|
|
153
|
+
}
|
|
154
|
+
function Context(tryLocsList) {
|
|
155
|
+
this.tryEntries = [{
|
|
156
|
+
tryLoc: "root"
|
|
157
|
+
}], tryLocsList.forEach(pushTryEntry, this), this.reset(!0);
|
|
158
|
+
}
|
|
159
|
+
function values(iterable) {
|
|
160
|
+
if (iterable) {
|
|
161
|
+
var iteratorMethod = iterable[iteratorSymbol];
|
|
162
|
+
if (iteratorMethod) return iteratorMethod.call(iterable);
|
|
163
|
+
if ("function" == typeof iterable.next) return iterable;
|
|
164
|
+
if (!isNaN(iterable.length)) {
|
|
165
|
+
var i = -1,
|
|
166
|
+
next = function next() {
|
|
167
|
+
for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next;
|
|
168
|
+
return next.value = undefined, next.done = !0, next;
|
|
169
|
+
};
|
|
170
|
+
return next.next = next;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return {
|
|
174
|
+
next: doneResult
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
function doneResult() {
|
|
178
|
+
return {
|
|
179
|
+
value: undefined,
|
|
180
|
+
done: !0
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", {
|
|
184
|
+
value: GeneratorFunctionPrototype,
|
|
185
|
+
configurable: !0
|
|
186
|
+
}), defineProperty(GeneratorFunctionPrototype, "constructor", {
|
|
187
|
+
value: GeneratorFunction,
|
|
188
|
+
configurable: !0
|
|
189
|
+
}), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) {
|
|
190
|
+
var ctor = "function" == typeof genFun && genFun.constructor;
|
|
191
|
+
return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name));
|
|
192
|
+
}, exports.mark = function (genFun) {
|
|
193
|
+
return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun;
|
|
194
|
+
}, exports.awrap = function (arg) {
|
|
195
|
+
return {
|
|
196
|
+
__await: arg
|
|
197
|
+
};
|
|
198
|
+
}, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
|
|
199
|
+
return this;
|
|
200
|
+
}), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
|
|
201
|
+
void 0 === PromiseImpl && (PromiseImpl = Promise);
|
|
202
|
+
var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
|
|
203
|
+
return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) {
|
|
204
|
+
return result.done ? result.value : iter.next();
|
|
205
|
+
});
|
|
206
|
+
}, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () {
|
|
207
|
+
return this;
|
|
208
|
+
}), define(Gp, "toString", function () {
|
|
209
|
+
return "[object Generator]";
|
|
210
|
+
}), exports.keys = function (val) {
|
|
211
|
+
var object = Object(val),
|
|
212
|
+
keys = [];
|
|
213
|
+
for (var key in object) keys.push(key);
|
|
214
|
+
return keys.reverse(), function next() {
|
|
215
|
+
for (; keys.length;) {
|
|
216
|
+
var key = keys.pop();
|
|
217
|
+
if (key in object) return next.value = key, next.done = !1, next;
|
|
218
|
+
}
|
|
219
|
+
return next.done = !0, next;
|
|
220
|
+
};
|
|
221
|
+
}, exports.values = values, Context.prototype = {
|
|
222
|
+
constructor: Context,
|
|
223
|
+
reset: function (skipTempReset) {
|
|
224
|
+
if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined);
|
|
225
|
+
},
|
|
226
|
+
stop: function () {
|
|
227
|
+
this.done = !0;
|
|
228
|
+
var rootRecord = this.tryEntries[0].completion;
|
|
229
|
+
if ("throw" === rootRecord.type) throw rootRecord.arg;
|
|
230
|
+
return this.rval;
|
|
231
|
+
},
|
|
232
|
+
dispatchException: function (exception) {
|
|
233
|
+
if (this.done) throw exception;
|
|
234
|
+
var context = this;
|
|
235
|
+
function handle(loc, caught) {
|
|
236
|
+
return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught;
|
|
237
|
+
}
|
|
238
|
+
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
239
|
+
var entry = this.tryEntries[i],
|
|
240
|
+
record = entry.completion;
|
|
241
|
+
if ("root" === entry.tryLoc) return handle("end");
|
|
242
|
+
if (entry.tryLoc <= this.prev) {
|
|
243
|
+
var hasCatch = hasOwn.call(entry, "catchLoc"),
|
|
244
|
+
hasFinally = hasOwn.call(entry, "finallyLoc");
|
|
245
|
+
if (hasCatch && hasFinally) {
|
|
246
|
+
if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
|
|
247
|
+
if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
|
|
248
|
+
} else if (hasCatch) {
|
|
249
|
+
if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
|
|
250
|
+
} else {
|
|
251
|
+
if (!hasFinally) throw new Error("try statement without catch or finally");
|
|
252
|
+
if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
},
|
|
257
|
+
abrupt: function (type, arg) {
|
|
258
|
+
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
259
|
+
var entry = this.tryEntries[i];
|
|
260
|
+
if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
|
|
261
|
+
var finallyEntry = entry;
|
|
262
|
+
break;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null);
|
|
266
|
+
var record = finallyEntry ? finallyEntry.completion : {};
|
|
267
|
+
return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record);
|
|
268
|
+
},
|
|
269
|
+
complete: function (record, afterLoc) {
|
|
270
|
+
if ("throw" === record.type) throw record.arg;
|
|
271
|
+
return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel;
|
|
272
|
+
},
|
|
273
|
+
finish: function (finallyLoc) {
|
|
274
|
+
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
275
|
+
var entry = this.tryEntries[i];
|
|
276
|
+
if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel;
|
|
277
|
+
}
|
|
278
|
+
},
|
|
279
|
+
catch: function (tryLoc) {
|
|
280
|
+
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
281
|
+
var entry = this.tryEntries[i];
|
|
282
|
+
if (entry.tryLoc === tryLoc) {
|
|
283
|
+
var record = entry.completion;
|
|
284
|
+
if ("throw" === record.type) {
|
|
285
|
+
var thrown = record.arg;
|
|
286
|
+
resetTryEntry(entry);
|
|
287
|
+
}
|
|
288
|
+
return thrown;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
throw new Error("illegal catch attempt");
|
|
292
|
+
},
|
|
293
|
+
delegateYield: function (iterable, resultName, nextLoc) {
|
|
294
|
+
return this.delegate = {
|
|
295
|
+
iterator: values(iterable),
|
|
296
|
+
resultName: resultName,
|
|
297
|
+
nextLoc: nextLoc
|
|
298
|
+
}, "next" === this.method && (this.arg = undefined), ContinueSentinel;
|
|
299
|
+
}
|
|
300
|
+
}, exports;
|
|
301
|
+
}
|
|
302
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
303
|
+
try {
|
|
304
|
+
var info = gen[key](arg);
|
|
305
|
+
var value = info.value;
|
|
306
|
+
} catch (error) {
|
|
307
|
+
reject(error);
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
310
|
+
if (info.done) {
|
|
311
|
+
resolve(value);
|
|
312
|
+
} else {
|
|
313
|
+
Promise.resolve(value).then(_next, _throw);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
function _asyncToGenerator(fn) {
|
|
317
|
+
return function () {
|
|
318
|
+
var self = this,
|
|
319
|
+
args = arguments;
|
|
320
|
+
return new Promise(function (resolve, reject) {
|
|
321
|
+
var gen = fn.apply(self, args);
|
|
322
|
+
function _next(value) {
|
|
323
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
324
|
+
}
|
|
325
|
+
function _throw(err) {
|
|
326
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
327
|
+
}
|
|
328
|
+
_next(undefined);
|
|
329
|
+
});
|
|
330
|
+
};
|
|
331
|
+
}
|
|
1
332
|
function _classCallCheck(instance, Constructor) {
|
|
2
333
|
if (!(instance instanceof Constructor)) {
|
|
3
334
|
throw new TypeError("Cannot call a class as a function");
|
|
@@ -139,78 +470,112 @@ var UniRequest = /*#__PURE__*/function () {
|
|
|
139
470
|
var requestedToken = false;
|
|
140
471
|
var retryCount = 0;
|
|
141
472
|
return new Promise(function (res, rej) {
|
|
142
|
-
var retryFucntion = function
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
timeout: params.timeout || _this3.timeout
|
|
155
|
-
})).then(function (resData) {
|
|
156
|
-
var statusCode = resData.statusCode,
|
|
157
|
-
data = resData.data;
|
|
158
|
-
if (statusCode === 200) {
|
|
159
|
-
if (!data.errno) {
|
|
160
|
-
var jsonData = data;
|
|
161
|
-
/** 如果是上传API的话,返回的结果需要解析成json对象 */
|
|
162
|
-
if (Object.prototype.toString.call(data) !== '[object Object]' && callbackPromise === uploadFilePromise) {
|
|
163
|
-
try {
|
|
164
|
-
jsonData = JSON.parse(data);
|
|
165
|
-
} catch (error) {
|
|
166
|
-
console.error(error);
|
|
167
|
-
_this3.rejectHandler(rej, resData);
|
|
473
|
+
var retryFucntion = /*#__PURE__*/function () {
|
|
474
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
475
|
+
var finalHeader, processedHeader;
|
|
476
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
477
|
+
while (1) switch (_context.prev = _context.next) {
|
|
478
|
+
case 0:
|
|
479
|
+
/** 因为token需要动态获取,因此放入这里 */
|
|
480
|
+
header[_this3.tokenHeader] = "".concat(_this3.tokenPrefix).concat(_this3.token);
|
|
481
|
+
/** 针对h5调试的时候,因为塞入cookie是不安全的,因此无需塞入cookie,使用登录页后,后端塞入的cookie */
|
|
482
|
+
// #ifdef H5
|
|
483
|
+
if (_this3.tokenHeader === 'cookie') {
|
|
484
|
+
delete header[_this3.tokenHeader];
|
|
168
485
|
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
486
|
+
// #endif
|
|
487
|
+
/** 执行请求头预处理 */
|
|
488
|
+
finalHeader = header;
|
|
489
|
+
if (!_this3.headerProcessor) {
|
|
490
|
+
_context.next = 15;
|
|
491
|
+
break;
|
|
492
|
+
}
|
|
493
|
+
_context.prev = 4;
|
|
494
|
+
_context.next = 7;
|
|
495
|
+
return _this3.headerProcessor(header);
|
|
496
|
+
case 7:
|
|
497
|
+
processedHeader = _context.sent;
|
|
498
|
+
finalHeader = Object.assign(Object.assign({}, header), processedHeader);
|
|
499
|
+
_context.next = 15;
|
|
500
|
+
break;
|
|
501
|
+
case 11:
|
|
502
|
+
_context.prev = 11;
|
|
503
|
+
_context.t0 = _context["catch"](4);
|
|
504
|
+
_this3.rejectHandler(rej, _context.t0);
|
|
505
|
+
return _context.abrupt("return");
|
|
506
|
+
case 15:
|
|
507
|
+
callbackPromise(Object.assign(Object.assign({}, params), {
|
|
508
|
+
header: finalHeader,
|
|
509
|
+
url: url,
|
|
510
|
+
timeout: params.timeout || _this3.timeout
|
|
511
|
+
})).then(function (resData) {
|
|
512
|
+
var statusCode = resData.statusCode,
|
|
513
|
+
data = resData.data;
|
|
514
|
+
if (statusCode === 200) {
|
|
515
|
+
if (!data.errno) {
|
|
516
|
+
var jsonData = data;
|
|
517
|
+
/** 如果是上传API的话,返回的结果需要解析成json对象 */
|
|
518
|
+
if (Object.prototype.toString.call(data) !== '[object Object]' && callbackPromise === uploadFilePromise) {
|
|
519
|
+
try {
|
|
520
|
+
jsonData = JSON.parse(data);
|
|
521
|
+
} catch (error) {
|
|
522
|
+
console.error(error);
|
|
523
|
+
_this3.rejectHandler(rej, resData);
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
res(jsonData.data);
|
|
527
|
+
} else {
|
|
528
|
+
_this3.rejectHandler(rej, resData);
|
|
529
|
+
}
|
|
530
|
+
/** 针对小网关进行的处理,历史遗留问题,需要兼容 */
|
|
531
|
+
} else if (403 === statusCode && !requestedToken) {
|
|
532
|
+
// #ifndef H5
|
|
533
|
+
(_this3.getTokenFun ? _this3.getTokenFun() : getToken(_this3.tokenEventName)).then(function (token) {
|
|
534
|
+
_this3.token = token;
|
|
535
|
+
requestedToken = true;
|
|
536
|
+
/** 获取token应该立马请求,不需要延迟 */
|
|
537
|
+
retryFucntion();
|
|
538
|
+
})["catch"](function () {
|
|
539
|
+
if (_this3.maxRetryCount > retryCount && !requestedToken) {
|
|
540
|
+
delayRetryFcuntion();
|
|
541
|
+
} else {
|
|
542
|
+
_this3.rejectHandler(rej, resData);
|
|
543
|
+
}
|
|
544
|
+
});
|
|
545
|
+
// #endif
|
|
546
|
+
// #ifdef H5
|
|
547
|
+
_this3.rejectHandler(rej, resData);
|
|
548
|
+
// #endif
|
|
549
|
+
/** 最新无权限处理方案,直接调用客户端logout事件,退出到登录页 */
|
|
550
|
+
} else if (401 === statusCode) {
|
|
551
|
+
_this3.rejectHandler(rej, resData);
|
|
552
|
+
uni.sendNativeEvent(EVENT_NAME.LOGOUT, {}, function () {
|
|
553
|
+
console.log('用户无权限,调用logout事件,退出到登录页');
|
|
554
|
+
});
|
|
555
|
+
} else {
|
|
556
|
+
if (_this3.maxRetryCount > retryCount && !requestedToken) {
|
|
557
|
+
delayRetryFcuntion();
|
|
558
|
+
} else {
|
|
559
|
+
_this3.rejectHandler(rej, resData);
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
})["catch"](function (rejData) {
|
|
563
|
+
if (_this3.maxRetryCount > retryCount && !requestedToken) {
|
|
564
|
+
delayRetryFcuntion();
|
|
565
|
+
} else {
|
|
566
|
+
_this3.rejectHandler(rej, rejData);
|
|
567
|
+
}
|
|
568
|
+
});
|
|
569
|
+
case 16:
|
|
570
|
+
case "end":
|
|
571
|
+
return _context.stop();
|
|
204
572
|
}
|
|
205
|
-
}
|
|
206
|
-
})
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
}
|
|
212
|
-
});
|
|
213
|
-
};
|
|
573
|
+
}, _callee, null, [[4, 11]]);
|
|
574
|
+
}));
|
|
575
|
+
return function retryFucntion() {
|
|
576
|
+
return _ref.apply(this, arguments);
|
|
577
|
+
};
|
|
578
|
+
}();
|
|
214
579
|
var delayRetryFcuntion = function delayRetryFcuntion() {
|
|
215
580
|
setTimeout(function () {
|
|
216
581
|
retryCount++;
|