@seayoo-web/request 3.5.2 → 4.0.1

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.
@@ -0,0 +1,645 @@
1
+ const f = typeof globalThis < "u" ? globalThis : typeof self < "u" ? self : typeof window < "u" ? window : Function("return this")();
2
+ function C() {
3
+ return f;
4
+ }
5
+ function m(e) {
6
+ return typeof e == "function";
7
+ }
8
+ function O(e) {
9
+ return typeof e == "object" && e !== null;
10
+ }
11
+ function P() {
12
+ return "wx" in f && O(f.wx) && "getSystemInfo" in f.wx && m(f.wx.getSystemInfo);
13
+ }
14
+ function we() {
15
+ return "fetch" in f && m(f.fetch);
16
+ }
17
+ function be() {
18
+ return "window" in f && O(f.window) && !P();
19
+ }
20
+ function R() {
21
+ return "Blob" in f && m(f.Blob);
22
+ }
23
+ function U() {
24
+ return "FormData" in f && m(f.FormData);
25
+ }
26
+ function M() {
27
+ return "TextDecoder" in f && m(f.TextDecoder);
28
+ }
29
+ function Ee() {
30
+ return "AbortController" in f && m(f.AbortController);
31
+ }
32
+ function q() {
33
+ return "URLSearchParams" in f && m(f.URLSearchParams);
34
+ }
35
+ function H(e) {
36
+ return new Promise((t) => setTimeout(t, Math.min(Number.MAX_SAFE_INTEGER, Math.max(0, e))));
37
+ }
38
+ // @__NO_SIDE_EFFECTS__
39
+ function N(e) {
40
+ const t = e || "CustomError";
41
+ return class extends Error {
42
+ constructor(n) {
43
+ super(n), Object.defineProperty(this, "name", {
44
+ value: t,
45
+ enumerable: !1,
46
+ configurable: !0
47
+ }), "setPrototypeOf" in Object && Object.setPrototypeOf(this, new.target.prototype), "captureStackTrace" in Error && typeof Error.captureStackTrace == "function" && Error.captureStackTrace(this, this.constructor);
48
+ }
49
+ };
50
+ }
51
+ const I = /^(?:https?:)?\/\/.+$/i, G = /^https?:\/\/.+$/i, K = /^\{[\d\D]*\}$/, _ = /^\[[\d\D]*\]$/;
52
+ function $(e, t = !1) {
53
+ return t ? I.test(e) : G.test(e);
54
+ }
55
+ function F(e) {
56
+ return e == null;
57
+ }
58
+ function A(e, ...t) {
59
+ if (!e || typeof e != "object") return !1;
60
+ const n = Object.getPrototypeOf(e);
61
+ return n !== Object.prototype && n !== null ? !1 : t.every((s) => s in e);
62
+ }
63
+ function S(e) {
64
+ return K.test(e) || _.test(e);
65
+ }
66
+ function E(e, t) {
67
+ try {
68
+ const n = JSON.parse(e);
69
+ return t ? t(n) ? n : null : n;
70
+ } catch {
71
+ return null;
72
+ }
73
+ }
74
+ async function Te(e) {
75
+ return await new Promise(function(t) {
76
+ const n = document.getElementsByTagName("head")[0], s = document.createElement("script");
77
+ s.setAttribute("type", "text/javascript"), s.setAttribute("charset", "utf-8"), s.onload = function() {
78
+ n.removeChild(s), t(!0);
79
+ }, s.onerror = function() {
80
+ n.removeChild(s), t(!1);
81
+ }, s.setAttribute("src", e), n.appendChild(s);
82
+ });
83
+ }
84
+ function J(e, t = "数据未能正确识别") {
85
+ return typeof e == "function" ? {
86
+ guard: e,
87
+ message: t
88
+ } : {
89
+ guard: e.guard,
90
+ message: e.message || t
91
+ };
92
+ }
93
+ function V(e, t = "") {
94
+ return !t || $(e, !0) ? j(e) : (j(t) + "/" + e).replace(/\/{2,}/g, "/").replace(/:\//, "://");
95
+ }
96
+ function j(e) {
97
+ const t = C();
98
+ return $(e, !0) ? e.startsWith("http") ? e : ("location" in t ? location.protocol : "https:") + e : ("location" in t ? location.origin : "http://127.0.0.1") + "/" + e.replace(/^\/+/, "");
99
+ }
100
+ function W(e, t) {
101
+ const n = {};
102
+ return (e.match(/([^=&#?]+)=[^&#]*/g) || []).forEach(function(s) {
103
+ const r = s.split("="), o = r[0], a = decodeURIComponent(r[1] || "");
104
+ n[o] !== void 0 ? n[o] += "," + a : n[o] = a;
105
+ }), t !== !0 ? n[t] || "" : n;
106
+ }
107
+ function X(e, t) {
108
+ if (t) {
109
+ if (t === !0)
110
+ return e.replace(/\?[^#]*/, "");
111
+ } else return e;
112
+ const n = e.split("#"), s = n[0].split("?"), r = s[0], o = s.length > 1 ? s[1] : "", a = n.length > 1 ? "#" + n[1] : "", i = typeof t == "string" ? [t] : Array.isArray(t) ? t : [];
113
+ return !i.length || !o ? n[0] + a : (i.map((c) => c.replace(/([\\(){}[\]^$+\-*?|])/g, "\\$1")), (r + "?" + o.replace(new RegExp("(?:^|&)(?:" + i.join("|") + ")=[^&$]+", "g"), "").replace(/^&/, "")).replace(/\?$/, "") + a);
114
+ }
115
+ function z(e, t, n = !1) {
116
+ const s = typeof t == "string" ? t : Object.keys(t).map((a) => `${a}=${encodeURIComponent(t[a])}`).join("&");
117
+ if (!s)
118
+ return e;
119
+ const r = e.split("#");
120
+ n && (r[0] = X(
121
+ r[0],
122
+ (s.match(/([^=&#?]+)=[^&#]+/g) || []).map((a) => a.replace(/=.+$/, ""))
123
+ ));
124
+ const o = r[0].indexOf("?") + 1 ? "&" : "?";
125
+ return (r[0] + o + s + (r.length > 1 ? "#" + r[1] : "")).replace(/\?&/, "?");
126
+ }
127
+ function Q(e) {
128
+ const t = e.match(/(?:\?|&)([^=]+)(?:&|$)/g);
129
+ return t ? t.join("").replace(/(?:\?|^&+|&+$)/g, "").replace(/&{2}/g, "&").split("&").sort() : [];
130
+ }
131
+ class Y {
132
+ ttl;
133
+ cache;
134
+ timer = null;
135
+ // 定时循环以清理缓存
136
+ loopCheck() {
137
+ if (Object.keys(this.cache).forEach((n) => {
138
+ this.cache[n].ttl < Date.now() && delete this.cache[n];
139
+ }), Object.keys(this.cache).length === 0) {
140
+ this.timer = null;
141
+ return;
142
+ }
143
+ this.timer = setTimeout(this.loopCheck, 5e3);
144
+ }
145
+ constructor(t = 500) {
146
+ this.cache = {}, this.ttl = Math.max(t, 0), this.loopCheck = this.loopCheck.bind(this);
147
+ }
148
+ getKey(t, n, s, r) {
149
+ if (t.toLowerCase() !== "get" && !r)
150
+ return "";
151
+ const o = t.toLowerCase(), a = n.replace(/#.+/, ""), i = a.replace(/\?.+/g, "");
152
+ if (r)
153
+ try {
154
+ const h = r() || "";
155
+ return h ? `${i}_${o}_${h}` : "";
156
+ } catch (h) {
157
+ return console.warn("[RequestCache] cacheResolve error", n, s, h), "";
158
+ }
159
+ const c = Object.assign(W(a, !0), s), l = Q(a), u = Object.keys(c).sort().map((h) => `${h}#${c[h]}`);
160
+ return `${i}_${o}_${u.join(",")}_${l.join(",")}`;
161
+ }
162
+ updateTTL(t) {
163
+ this.ttl = Math.max(t, 0);
164
+ }
165
+ get(t, n) {
166
+ if (Math.max(n ?? this.ttl, 0) === 0)
167
+ return null;
168
+ const r = this.cache[t];
169
+ return r ? r.ttl < Date.now() ? (delete this.cache[t], null) : r.res : null;
170
+ }
171
+ set(t, n, s) {
172
+ const r = Math.max(s ?? this.ttl, 0);
173
+ r !== 0 && (this.cache[t] = {
174
+ ttl: Date.now() + r,
175
+ res: n
176
+ }, this.timer === null && (this.timer = setTimeout(this.loopCheck, 5e3)));
177
+ }
178
+ del(t) {
179
+ this.cache[t] && delete this.cache[t];
180
+ }
181
+ }
182
+ class Z {
183
+ // 保存的配置需要部分字段强制设置默认值
184
+ config = {
185
+ baseURL: "/",
186
+ maxRetry: 1,
187
+ retryInterval: 200,
188
+ retryResolve: "default",
189
+ timeout: 1e4,
190
+ cacheTTL: 500,
191
+ credentials: "same-origin",
192
+ defaultTypeGuardMessage: "响应数据未能正确识别",
193
+ responseRule: {
194
+ ok: {
195
+ resolve: "body"
196
+ },
197
+ failed: {
198
+ resolve: "json",
199
+ messageField: "message"
200
+ }
201
+ }
202
+ };
203
+ constructor(t) {
204
+ t && this.set(t);
205
+ }
206
+ set(t) {
207
+ if (t.baseURL && !/^\/.+/.test(t.baseURL) && !$(t.baseURL))
208
+ throw console.warn("baseURL 需要以 / 开头,或者是完整的 url 地址"), new Error("BaseURLError");
209
+ Object.assign(this.config, t);
210
+ }
211
+ get(t) {
212
+ return this.config[t];
213
+ }
214
+ /** 基于 baseURL 返回完整的 url 地址 */
215
+ getFullUrl(t) {
216
+ return V(t, this.config.baseURL);
217
+ }
218
+ /** 提示消息 */
219
+ showMessage(t, n, s, r) {
220
+ this.config.messageHandler && n && this.config.messageHandler(t, n, s, r);
221
+ }
222
+ }
223
+ const y = {
224
+ /** 响应数据校验失败 */
225
+ UnexpectResponse: "UnexpectResponse",
226
+ /** 请求被取消 */
227
+ Aborted: "Aborted",
228
+ /** 未知错误 */
229
+ Unknown: "Unknown",
230
+ /** 网络错误 */
231
+ NetworkError: "NetworkError",
232
+ /** 超时 */
233
+ Timeout: "Timeout",
234
+ /** 请求方法不被支持,在微信小程序环境下有效 */
235
+ NotSupport: "NotSupport"
236
+ };
237
+ function ee(e, t, n, s) {
238
+ if (t.ok && !F(t.data) && s) {
239
+ const { guard: r, message: o } = J(s, n.get("defaultTypeGuardMessage"));
240
+ return r(t.data) || (t.code = y.UnexpectResponse, n.showMessage(!0, `${e} ${o}`, t.code, t.status), console.error(t.code, e, t.data), t.data = null, t.message = o), t;
241
+ }
242
+ return t;
243
+ }
244
+ class ke {
245
+ agent;
246
+ config;
247
+ cache;
248
+ constructor(t, n) {
249
+ this.config = new Z(n), this.agent = t, this.cache = new Y(this.config.get("cacheTTL")), this.setConfig = this.setConfig.bind(this), this.getConfig = this.getConfig.bind(this), this.request = this.request.bind(this), this.get = this.get.bind(this), this.post = this.post.bind(this), this.del = this.del.bind(this), this.patch = this.patch.bind(this), this.put = this.put.bind(this), this.head = this.head.bind(this);
250
+ }
251
+ /** 发送网络请求,含有缓存控制逻辑,不含有 guard 逻辑 */
252
+ async send(t, n) {
253
+ const s = this.cache.getKey(n?.method || "GET", t, n?.params, n?.cacheResolve);
254
+ if (s) {
255
+ const r = this.cache.get(s, n?.cacheTTL);
256
+ if (r)
257
+ return await r;
258
+ }
259
+ try {
260
+ const r = this.agent(t, this.config, n);
261
+ s && this.cache.set(s, r, n?.cacheTTL);
262
+ const o = await r;
263
+ return (!o.ok || o.status < 0) && this.cache.del(s), o;
264
+ } catch (r) {
265
+ return console.error("RequestError", r), {
266
+ ok: !1,
267
+ status: -1,
268
+ code: y.Unknown,
269
+ message: r instanceof Error ? r.message : String(r),
270
+ headers: {},
271
+ data: null
272
+ };
273
+ }
274
+ }
275
+ async request(t) {
276
+ const n = await this.send(t.url, t.options);
277
+ return ee(t.url, n, this.config, t.guard ?? null);
278
+ }
279
+ /** 整理合并通用参数 */
280
+ gen(t, n, s, r, o) {
281
+ const a = Object.assign(
282
+ o ? { ...o, method: n } : { method: n },
283
+ r ? { body: r } : null,
284
+ s ? { params: s } : null
285
+ );
286
+ return typeof t == "object" ? (a.params = t.params, { options: a, url: t.url }) : { options: a, url: t };
287
+ }
288
+ /**
289
+ * 修改默认请求配置: baseURL / timeout / credentials / errorHandler / messageHandler / responseHandler / logHandler / responseRule
290
+ */
291
+ setConfig(t) {
292
+ this.config.set(t), this.cache.updateTTL(this.config.get("cacheTTL"));
293
+ }
294
+ /**
295
+ * 读取默认的请求配置
296
+ */
297
+ getConfig(t) {
298
+ return this.config.get(t);
299
+ }
300
+ /**
301
+ * 发送一个 HEAD 请求,并且不处理响应 body
302
+ */
303
+ async head(t, n, s) {
304
+ return this.request(this.gen(t, "HEAD", n, null, s));
305
+ }
306
+ async get(t, n, s, r) {
307
+ const o = this.gen(t, "GET", n, null, r);
308
+ return s ? this.request({ ...o, guard: s }) : this.request(o);
309
+ }
310
+ async post(t, n, s, r) {
311
+ const o = this.gen(t, "POST", null, n, r);
312
+ return s ? this.request({ ...o, guard: s }) : this.request(o);
313
+ }
314
+ async del(t, n, s, r) {
315
+ const o = this.gen(t, "DELETE", n, null, r);
316
+ return s ? this.request({ ...o, guard: s }) : this.request(o);
317
+ }
318
+ async put(t, n, s, r) {
319
+ const o = this.gen(t, "PUT", null, n, r);
320
+ return s ? this.request({ ...o, guard: s }) : this.request(o);
321
+ }
322
+ async patch(t, n, s, r) {
323
+ const o = this.gen(t, "PATCH", null, n, r);
324
+ return s ? this.request({ ...o, guard: s }) : this.request(o);
325
+ }
326
+ }
327
+ function te(e) {
328
+ const t = {};
329
+ for (const [n, s] of e)
330
+ n && typeof n == "string" && (t[n] = s || "");
331
+ return t;
332
+ }
333
+ function se(e) {
334
+ const t = {};
335
+ return e && Object.keys(e).forEach((n) => {
336
+ const s = e[n], r = s == null ? "" : typeof s == "boolean" || typeof s == "number" ? String(s) : s;
337
+ r && (t[n] = r);
338
+ }), t;
339
+ }
340
+ function L(e) {
341
+ return F(e) ? "" : typeof e == "string" ? e : e instanceof ArrayBuffer && M() ? new TextDecoder().decode(e) : JSON.stringify(e);
342
+ }
343
+ function ne(e) {
344
+ return e instanceof Error ? e : new Error(L(e));
345
+ }
346
+ async function Re(e) {
347
+ if (M())
348
+ return new TextEncoder().encode(e).buffer;
349
+ if (R())
350
+ return await new Blob([e]).arrayBuffer();
351
+ throw new Error("cannot convert string to ArrayBuffer");
352
+ }
353
+ function re(e, t) {
354
+ if ("URL" in C()) {
355
+ const s = new URL(e);
356
+ return Object.keys(t).forEach((r) => s.searchParams.set(r, t[r])), s.toString();
357
+ }
358
+ return z(e, t);
359
+ }
360
+ function oe(e) {
361
+ return typeof e == "function" ? e : Array.isArray(e) && e.length > 0 ? function(t) {
362
+ return e.includes(t.status);
363
+ } : e === "network" ? ae : ce;
364
+ }
365
+ function ae({ error: e }) {
366
+ return e === y.NetworkError;
367
+ }
368
+ function ce({ status: e, headers: t, error: n }) {
369
+ return n === y.NetworkError ? !0 : t?.server === "TencentEdgeOne" ? e === 522 || e === 552 : !1;
370
+ }
371
+ async function $e(e, t, n) {
372
+ const s = Object.assign({ method: "GET" }, n), r = U() ? s.body instanceof FormData : !1, o = r && s.method !== "POST" && s.method !== "PUT" ? "POST" : s.method, a = o === "GET" || o === "HEAD" || o === "DELETE";
373
+ a && s.body !== void 0 && (console.warn("request body is invalid with method get, head, delete"), delete s.body);
374
+ const i = Object.assign(
375
+ r || a ? {} : {
376
+ "Content-Type": R() && s.body instanceof Blob ? s.body.type || "application/octet-stream" : "application/json;charset=utf-8"
377
+ },
378
+ s.headers
379
+ ), c = t.getFullUrl(e), l = se(s.params), u = ie(s.body), h = s.timeout || t.get("timeout"), p = await (async function() {
380
+ const g = t.get("requestTransformer");
381
+ if (g)
382
+ return await g({ headers: i, params: l, method: o, url: c, body: u });
383
+ })(), d = re(typeof p == "string" && p ? p : c, l);
384
+ return t.get("logHandler")?.({ type: "ready", url: d, method: o, headers: i, timeout: h, body: u }), {
385
+ url: d,
386
+ method: o,
387
+ body: u,
388
+ headers: i,
389
+ timeout: h,
390
+ abort: s.abort,
391
+ asBuffer: !!s.asBuffer,
392
+ credentials: s.credentials || t.get("credentials")
393
+ };
394
+ }
395
+ function ie(e) {
396
+ if (e)
397
+ return typeof e == "string" || q() && e instanceof URLSearchParams || e instanceof ArrayBuffer || R() && e instanceof Blob || U() && e instanceof FormData ? e : JSON.stringify(e);
398
+ }
399
+ const B = "data", w = "message";
400
+ function ue(e, t, n) {
401
+ return D(e.status) ? fe(n?.ok || t.ok, e) : he(n?.failed || t.failed, e);
402
+ }
403
+ function fe(e, { statusText: t, body: n }) {
404
+ const s = {
405
+ ok: !0,
406
+ code: t,
407
+ message: "",
408
+ data: null
409
+ };
410
+ if (!n)
411
+ return s;
412
+ if (typeof n != "string")
413
+ return s.data = n, s;
414
+ if (e.resolve === "body")
415
+ return s.data = S(n) ? T(E(n), e.converter) : n, s;
416
+ const r = E(n);
417
+ if (!r)
418
+ return s.ok = !1, s.code = "ResponseFormatError", s.message = "响应内容无法解析为 json", s;
419
+ const o = T(r, e.converter);
420
+ if (!o || !A(o))
421
+ return s.ok = !1, s.code = "ResponseFormatError", s.message = "响应内容无法格式化为 object", s;
422
+ const a = e.statusField;
423
+ if (a && !(a in o))
424
+ return s.ok = !1, s.code = "ResponseFieldMissing", s.message = `响应内容找不到状态字段 ${a}`, s;
425
+ const i = e.statusOKValue || "", c = e.dataField || B, l = e.messageField || w, u = a ? String(o[a] ?? "") : "";
426
+ return s.ok = a ? u === i : !0, s.code = u || s.code, s.data = c === !0 ? o : c in o ? o[c] : null, s.message = k(o, l), e.ignoreMessage && s.message && (Array.isArray(e.ignoreMessage) ? e.ignoreMessage.includes(s.message) : e.ignoreMessage === s.message) && (s.message = ""), s;
427
+ }
428
+ function he(e, { statusText: t, body: n, error: s }) {
429
+ const r = typeof n == "string" ? n : "", o = {
430
+ ok: !1,
431
+ code: s || t,
432
+ message: r,
433
+ data: null
434
+ };
435
+ switch (e.resolve) {
436
+ case "body":
437
+ o.message = x(r) || r;
438
+ break;
439
+ case "json":
440
+ const { code: a, message: i } = le(r, e.converter, e.statusField, e.messageField);
441
+ o.code = a || s || t, o.message = x(r) || i;
442
+ break;
443
+ }
444
+ return o;
445
+ }
446
+ function D(e) {
447
+ return e >= 200 && e < 400;
448
+ }
449
+ function T(e, t) {
450
+ return t && typeof t == "function" ? t(e) : e;
451
+ }
452
+ const je = function(e) {
453
+ const t = [], n = e.failed || { resolve: "json" };
454
+ switch (t.push("- 当http状态码 <200 或者 >=400 时"), n.resolve) {
455
+ case "body":
456
+ t.push(" 将响应内容格式化为字符串并作为错误消息");
457
+ break;
458
+ case "json":
459
+ t.push(" 将响应解析为json,并读取 " + (n.messageField || w) + " 作为错误消息");
460
+ break;
461
+ }
462
+ const s = e.ok || { resolve: "body" };
463
+ switch (t.push("- 当http状态码 >=200 并且 <400 时"), s.resolve) {
464
+ case "body":
465
+ t.push(" 将响应尝试解析为 json,并作为数据内容返回");
466
+ break;
467
+ case "json":
468
+ t.push(
469
+ " 将响应解析为 json,读取 " + (s.dataField || B) + " 作为响应数据,读取 " + (s.messageField || w) + " 作为提示消息"
470
+ ), s.statusField && t.push(
471
+ " 当 " + s.statusField + " 为 " + (s.statusOKValue || "空值") + " 时是成功提示,否则是错误消息"
472
+ ), s.ignoreMessage && t.push(" 并忽略以下消息:" + s.ignoreMessage);
473
+ break;
474
+ }
475
+ return t.join(`
476
+ `);
477
+ };
478
+ function le(e, t, n, s = w) {
479
+ if (!S(e))
480
+ return { message: "" };
481
+ const r = T(E(e), t);
482
+ return !r || !A(r) ? { message: e } : {
483
+ code: n ? k(r, n) : "",
484
+ message: k(r, s) || e
485
+ };
486
+ }
487
+ function k(e, t) {
488
+ const n = Array.isArray(t) ? t : [t];
489
+ for (const s of n)
490
+ if (s in e)
491
+ return L(e[s]);
492
+ return "";
493
+ }
494
+ const de = [/<title>([^<]+)<\/title>/i, /<message>([^<]+)<\/message>/i];
495
+ function x(e) {
496
+ for (const t of de) {
497
+ const n = e.match(t);
498
+ if (n)
499
+ return n[1];
500
+ }
501
+ return "";
502
+ }
503
+ const ge = /* @__PURE__ */ N("APIError");
504
+ function pe(e) {
505
+ const t = {};
506
+ for (const r in e.headers)
507
+ (r.startsWith("x-") || r.includes("trace") || r.includes("server") || r.includes("status") || /\b(?:id|uuid)\b/.test(r)) && (t[r] = e.headers[r]);
508
+ const n = e.url.replace(/^(?:https?:)?\/*/i, "").replace(/\?.+/, ""), s = e.status < 0 ? "unknown" : e.status;
509
+ return {
510
+ sentryError: new ge(`${n}${s === "unknown" ? "" : ` | ${s}`} | ${e.code}`),
511
+ sentryTags: {
512
+ ...t,
513
+ status: s,
514
+ method: e.method,
515
+ code: e.code || "unknown",
516
+ message: e.message || "empty"
517
+ },
518
+ sentryExtra: {
519
+ url: e.url,
520
+ responseBody: typeof e.body == "string" || e.body === null ? e.body || "empty" : "[ArrayBuffer]",
521
+ responseHeaders: e.headers,
522
+ rawError: e.error
523
+ }
524
+ };
525
+ }
526
+ async function xe(e, t) {
527
+ if (e.method === "HEAD" || e.status === 204)
528
+ return e.body = null, e;
529
+ try {
530
+ e.body = t.asBuffer ? await t.buffer() : await t.text();
531
+ } catch (n) {
532
+ e.body = null, e.error = y.Unknown, e.rawError = ne(n);
533
+ }
534
+ return e;
535
+ }
536
+ function ve(e, t, n, s) {
537
+ const r = e.status, o = e.method, a = te(
538
+ Object.entries(e.headers || {}).map(([d, g]) => [d.toLowerCase(), g])
539
+ ), { ok: i, code: c, data: l, message: u } = ue(e, n.get("responseRule"), s?.responseRule);
540
+ if (!D(r)) {
541
+ const d = pe({
542
+ url: e.url,
543
+ method: e.method,
544
+ status: r,
545
+ code: c,
546
+ message: u,
547
+ body: e.body,
548
+ headers: a,
549
+ error: e.rawError
550
+ });
551
+ (n.get("errorHandler") || me)({
552
+ url: t,
553
+ method: o,
554
+ status: r,
555
+ code: c,
556
+ message: u,
557
+ headers: a,
558
+ rawError: e.rawError,
559
+ ...d
560
+ });
561
+ }
562
+ if (r < 0)
563
+ return v(
564
+ { ok: !1, status: r, code: e.statusText, headers: {}, message: "", data: null },
565
+ `${o} ${t} ${e.statusText}`,
566
+ o,
567
+ t,
568
+ n,
569
+ s
570
+ );
571
+ const h = { ok: i, data: l, code: c, message: u, status: r, headers: a };
572
+ n.get("responseHandler")?.({ ...h }, o, t);
573
+ const p = i ? u : u || e.statusText;
574
+ return v(h, p, o, t, n, s);
575
+ }
576
+ function v(e, t, n, s, r, o) {
577
+ const a = r.get("message"), i = a === !1 || o?.message === !1 ? !1 : o?.message || a;
578
+ if (i !== !1) {
579
+ const c = typeof i == "function" ? i(e, n, s, t) : t;
580
+ c instanceof Error ? r.showMessage(!0, b(c.message), e.code, e.status) : c && typeof c == "object" && "message" in c && typeof c.message == "string" ? r.showMessage(!1, b(c.message), e.code, e.status) : c && r.showMessage(!e.ok, b(String(c)), e.code, e.status);
581
+ }
582
+ return e;
583
+ }
584
+ function me(e) {
585
+ const t = {};
586
+ for (const n in e)
587
+ n.startsWith("sentry") || (t[n] = e[n]);
588
+ console.error("RequestError", t);
589
+ }
590
+ function b(e) {
591
+ return e.replace(/<script[\s\S]*?>[\s\S]*?<\/script>/gi, "").replace(/<[^>]+>/g, "").trim();
592
+ }
593
+ async function ye(e, t, n, s, r) {
594
+ const o = r || 0, a = Math.max(0, Math.min(10, s?.maxRetry ?? n.get("maxRetry") ?? 0)), i = oe(s?.retryResolve ?? n.get("retryResolve")), c = n.get("logHandler");
595
+ c?.({
596
+ type: "prepare",
597
+ url: t,
598
+ method: s?.method || "GET",
599
+ retry: o,
600
+ maxRetry: a,
601
+ message: o === 0 ? "start" : `retry ${o}/${a} start`,
602
+ headers: s?.headers,
603
+ options: s
604
+ });
605
+ const l = Date.now(), u = await e(t, n, s), h = u.status, p = Date.now() - l, d = `[cost ${p}][${h}] ${h < 0 ? u.body : ""}`;
606
+ if (c?.({
607
+ type: "finished",
608
+ url: t,
609
+ method: u.method,
610
+ retry: o,
611
+ maxRetry: a,
612
+ message: o === 0 ? `finish ${d}` : `retry ${o}/${a} finish ${d}`,
613
+ response: u,
614
+ headers: u.headers,
615
+ cost: p
616
+ }), !a || o >= a || i(u, o) !== !0)
617
+ return u;
618
+ const g = s?.retryInterval ?? n.get("retryInterval") ?? 100;
619
+ return await H(
620
+ Math.max(
621
+ 100,
622
+ g === "2EB" ? Math.pow(2, o) * 100 : typeof g == "function" ? g(o + 1, { url: t, status: h, method: u.method }) || 0 : g
623
+ )
624
+ ), await ye(e, t, n, s, o + 1);
625
+ }
626
+ export {
627
+ P as E,
628
+ Z as G,
629
+ z as H,
630
+ ke as N,
631
+ y as R,
632
+ we as X,
633
+ Re as a,
634
+ se as b,
635
+ $e as c,
636
+ be as d,
637
+ te as e,
638
+ xe as f,
639
+ je as g,
640
+ ve as h,
641
+ Ee as i,
642
+ ye as r,
643
+ L as t,
644
+ Te as v
645
+ };