@seayoo-web/request 3.1.4 → 3.1.5
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/dist/index.cjs +2 -2
- package/dist/index.js +80 -77
- package/dist/node.cjs +1 -1
- package/dist/node.js +1 -1
- package/dist/{request.fetch-Cuk4gO1S.js → request.fetch-1poQOlEV.js} +14 -11
- package/dist/request.fetch-hlpQxV81.cjs +1 -0
- package/package.json +1 -1
- package/types/inc/type.d.ts +1 -1
- package/dist/request.fetch-COXrFv2v.cjs +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
2
|
-
`).forEach(n=>{const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./retry-8pExkGke.cjs"),m=require("./request.fetch-hlpQxV81.cjs"),y=async function(t,s,e){return r.handleResponse(await r.retryRequest(p,t,s,e),t,s,e)};async function E(t,s,e,n){const o=e==null?void 0:e.body,i=(e==null?void 0:e.method)==="PUT"?"PUT":"POST";if(s instanceof Blob){const u=new r.RequestGlobalConfig(n),f=await p(t,u,{...e,method:i,body:s});return r.handleResponse(f,t,u,e)}const c=new FormData,d={...s};o instanceof Object&&Object.entries(o).forEach(([u,f])=>{f instanceof Blob?d[u]=f:Array.isArray(f)?f.forEach((a,h)=>{c.append(`${u}[${h}]`,String(a))}):c.append(u,String(f))});for(const u in d)c.append(u,d[u]);const b=new r.RequestGlobalConfig(n),R=await p(t,b,{...e,method:i,body:c});return r.handleResponse(R,t,b,e)}const p=async function(t,s,e){const n=await r.convertOptions(t,s,e),o=n.method,i=e==null?void 0:e.onUploadProgress,c=r.ge(n.url,n.params);return await new Promise(d=>{let b=null,R=!1;const u=function(){R||(a.abort(),R=!0)};function f(){b!==null&&clearTimeout(b),n.abort&&n.abort.removeEventListener("abort",u)}const a=new XMLHttpRequest;let h=!1;if(a.open(o,c,!0),i){let g=1;a.upload.addEventListener("progress",w=>{g=w.total,i({total:w.total,loaded:w.loaded})}),a.addEventListener("load",()=>{i({loaded:g,total:g})})}a.addEventListener("load",()=>{const g=a.status;f(),d({url:c,method:o,status:g,statusText:a.statusText,headers:T(a),body:o==="HEAD"||g===204?"":a.responseText})}),a.addEventListener("error",g=>{f(),d({url:c,method:o,status:a.status||-1,statusText:a.statusText||r.RequestInternalError.NetworkError,body:"",rawError:g})},!0),a.addEventListener("abort",()=>{f(),d({url:c,method:o,status:h?-1:0,statusText:h?r.RequestInternalError.Timeout:r.RequestInternalError.Aborted,body:""})}),Object.entries(n.headers).forEach(([g,w])=>{a.setRequestHeader(g,w)}),n.credentials==="include"&&(a.withCredentials=!0),a.send(n.body||void 0),n.abort&&n.abort.addEventListener("abort",u),n.timeout>0&&(b=setTimeout(function(){h=!0,u()},n.timeout))})};function T(t){const s={};if(!t)return s;const e=t.getAllResponseHeaders();return e&&e!=="null"&&e.replace(/\r/g,"").split(`
|
|
2
|
+
`).forEach(n=>{const o=n.trim();if(!o)return;const i=o.split(":"),c=i[0].trim();c&&(s[c]=(i[1]||"").trim())}),s}async function H(t,s,e={}){const n=window;"callback"in e||(e.callback="jsonxData"+Math.random().toString(16).slice(2));const o=e.callback+"";if(!t)return null;const i=r.ge(t,e,!0);return new Promise(c=>{n[o]=function(d){if(o in window&&delete n[o],s(d))return d;console.warn("response type check failed",t,d),c(null)},r.ce(i).catch(function(){c(null),delete n[o]})})}async function j(t,s,e={}){const n=window;return"var"in e||(e.var="jsonxData"+Math.random().toString(16).slice(2)),t?await r.ce(r.ge(t,e,!0)).then(()=>{const o=n[e.var+""];return s(o)?o:(console.warn("response type check failed",t,o),null)}).catch(()=>null):null}const x=async function(t,s,e){return await E(t,s,e,{baseURL:l.getConfig("baseURL"),logHandler:l.getConfig("logHandler"),errorHandler:l.getConfig("errorHandler"),requestTransformer:l.getConfig("requestTransformer"),messageHandler:l.getConfig("messageHandler"),responseHandler:l.getConfig("responseHandler")})};function q(t){if(!r.jt.window)throw new Error("Default Module Only Support In Browser");return r.jt.fetch?new r.NetRequestHandler(m.fetchRequest,t):new r.NetRequestHandler(y,t)}const l=q(),C=l.setConfig,L=l.request,S=l.head,k=l.get,v=l.post,D=l.del,U=l.put,O=l.patch;exports.RequestInternalError=r.RequestInternalError;exports.getResponseRulesDescription=r.getResponseRulesDescription;exports.NetRequest=q;exports.del=D;exports.get=k;exports.head=S;exports.jsonp=H;exports.jsonx=j;exports.patch=O;exports.post=v;exports.put=U;exports.request=L;exports.setGlobalConfig=C;exports.upload=x;
|
package/dist/index.js
CHANGED
|
@@ -1,91 +1,94 @@
|
|
|
1
|
-
import { h as
|
|
2
|
-
import { d as
|
|
3
|
-
import { f as
|
|
4
|
-
const
|
|
5
|
-
return
|
|
1
|
+
import { h as p, r as x, R as T, c as C, g as R, a as m, b as q, j as E, N as H } from "./retry-_AqXIa5P.js";
|
|
2
|
+
import { d as K } from "./retry-_AqXIa5P.js";
|
|
3
|
+
import { f as L } from "./request.fetch-1poQOlEV.js";
|
|
4
|
+
const j = async function(t, a, e) {
|
|
5
|
+
return p(await x(y, t, a, e), t, a, e);
|
|
6
6
|
};
|
|
7
|
-
async function
|
|
8
|
-
const r = e == null ? void 0 : e.body,
|
|
7
|
+
async function k(t, a, e, n) {
|
|
8
|
+
const r = e == null ? void 0 : e.body, i = (e == null ? void 0 : e.method) === "PUT" ? "PUT" : "POST";
|
|
9
9
|
if (a instanceof Blob) {
|
|
10
|
-
const l = new
|
|
10
|
+
const l = new T(n), u = await y(t, l, {
|
|
11
11
|
...e,
|
|
12
|
-
method:
|
|
12
|
+
method: i,
|
|
13
13
|
body: a
|
|
14
14
|
});
|
|
15
|
-
return
|
|
15
|
+
return p(u, t, l, e);
|
|
16
16
|
}
|
|
17
|
-
const s = new FormData(),
|
|
18
|
-
r instanceof Object && Object.entries(r).forEach(([l,
|
|
19
|
-
|
|
20
|
-
s.append(`${l}[${
|
|
21
|
-
}) : s.append(l, String(
|
|
17
|
+
const s = new FormData(), d = { ...a };
|
|
18
|
+
r instanceof Object && Object.entries(r).forEach(([l, u]) => {
|
|
19
|
+
u instanceof Blob ? d[l] = u : Array.isArray(u) ? u.forEach((o, g) => {
|
|
20
|
+
s.append(`${l}[${g}]`, String(o));
|
|
21
|
+
}) : s.append(l, String(u));
|
|
22
22
|
});
|
|
23
|
-
for (const l in
|
|
24
|
-
s.append(l,
|
|
25
|
-
const b = new
|
|
23
|
+
for (const l in d)
|
|
24
|
+
s.append(l, d[l]);
|
|
25
|
+
const b = new T(n), w = await y(t, b, {
|
|
26
26
|
...e,
|
|
27
|
-
method:
|
|
27
|
+
method: i,
|
|
28
28
|
body: s
|
|
29
29
|
});
|
|
30
|
-
return w
|
|
30
|
+
return p(w, t, b, e);
|
|
31
31
|
}
|
|
32
|
-
const
|
|
33
|
-
const n = await
|
|
34
|
-
return await new Promise((
|
|
35
|
-
let b = null,
|
|
32
|
+
const y = async function(t, a, e) {
|
|
33
|
+
const n = await C(t, a, e), r = n.method, i = e == null ? void 0 : e.onUploadProgress, s = R(n.url, n.params);
|
|
34
|
+
return await new Promise((d) => {
|
|
35
|
+
let b = null, w = !1;
|
|
36
36
|
const l = function() {
|
|
37
|
-
|
|
37
|
+
w || (o.abort(), w = !0);
|
|
38
38
|
};
|
|
39
|
-
function
|
|
39
|
+
function u() {
|
|
40
40
|
b !== null && clearTimeout(b), n.abort && n.abort.removeEventListener("abort", l);
|
|
41
41
|
}
|
|
42
42
|
const o = new XMLHttpRequest();
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
43
|
+
let g = !1;
|
|
44
|
+
if (o.open(r, s, !0), i) {
|
|
45
|
+
let f = 1;
|
|
46
|
+
o.upload.addEventListener("progress", (h) => {
|
|
47
|
+
f = h.total, i({ total: h.total, loaded: h.loaded });
|
|
47
48
|
}), o.addEventListener("load", () => {
|
|
48
|
-
|
|
49
|
+
i({ loaded: f, total: f });
|
|
49
50
|
});
|
|
50
51
|
}
|
|
51
52
|
o.addEventListener("load", () => {
|
|
52
|
-
const
|
|
53
|
-
|
|
53
|
+
const f = o.status;
|
|
54
|
+
u(), d({
|
|
54
55
|
url: s,
|
|
55
56
|
method: r,
|
|
56
|
-
status:
|
|
57
|
+
status: f,
|
|
57
58
|
statusText: o.statusText,
|
|
58
|
-
headers:
|
|
59
|
-
body: r === "HEAD" ||
|
|
59
|
+
headers: S(o),
|
|
60
|
+
body: r === "HEAD" || f === 204 ? "" : o.responseText
|
|
60
61
|
});
|
|
61
62
|
}), o.addEventListener(
|
|
62
63
|
"error",
|
|
63
|
-
(
|
|
64
|
-
|
|
64
|
+
(f) => {
|
|
65
|
+
u(), d({
|
|
65
66
|
url: s,
|
|
66
67
|
method: r,
|
|
67
68
|
status: o.status || -1,
|
|
68
|
-
statusText: o.statusText ||
|
|
69
|
+
statusText: o.statusText || m.NetworkError,
|
|
69
70
|
body: "",
|
|
70
|
-
rawError:
|
|
71
|
+
rawError: f
|
|
71
72
|
});
|
|
72
73
|
},
|
|
73
74
|
!0
|
|
74
75
|
), o.addEventListener("abort", () => {
|
|
75
|
-
|
|
76
|
+
u(), d({
|
|
76
77
|
url: s,
|
|
77
78
|
method: r,
|
|
78
|
-
status: 0,
|
|
79
|
+
status: g ? -1 : 0,
|
|
79
80
|
// 设置为 0 可以防止自动重试的默认策略
|
|
80
|
-
statusText:
|
|
81
|
+
statusText: g ? m.Timeout : m.Aborted,
|
|
81
82
|
body: ""
|
|
82
83
|
});
|
|
83
|
-
}), Object.entries(n.headers).forEach(([
|
|
84
|
-
o.setRequestHeader(
|
|
85
|
-
}), n.credentials === "include" && (o.withCredentials = !0), o.send(n.body || void 0), n.abort && n.abort.addEventListener("abort", l), n.timeout > 0 && (b = setTimeout(
|
|
84
|
+
}), Object.entries(n.headers).forEach(([f, h]) => {
|
|
85
|
+
o.setRequestHeader(f, h);
|
|
86
|
+
}), n.credentials === "include" && (o.withCredentials = !0), o.send(n.body || void 0), n.abort && n.abort.addEventListener("abort", l), n.timeout > 0 && (b = setTimeout(function() {
|
|
87
|
+
g = !0, l();
|
|
88
|
+
}, n.timeout));
|
|
86
89
|
});
|
|
87
90
|
};
|
|
88
|
-
function
|
|
91
|
+
function S(t) {
|
|
89
92
|
const a = {};
|
|
90
93
|
if (!t)
|
|
91
94
|
return a;
|
|
@@ -95,36 +98,36 @@ function k(t) {
|
|
|
95
98
|
const r = n.trim();
|
|
96
99
|
if (!r)
|
|
97
100
|
return;
|
|
98
|
-
const
|
|
99
|
-
s && (a[s] = (
|
|
101
|
+
const i = r.split(":"), s = i[0].trim();
|
|
102
|
+
s && (a[s] = (i[1] || "").trim());
|
|
100
103
|
}), a;
|
|
101
104
|
}
|
|
102
|
-
async function
|
|
105
|
+
async function O(t, a, e = {}) {
|
|
103
106
|
const n = window;
|
|
104
107
|
"callback" in e || (e.callback = "jsonxData" + Math.random().toString(16).slice(2));
|
|
105
108
|
const r = e.callback + "";
|
|
106
109
|
if (!t)
|
|
107
110
|
return null;
|
|
108
|
-
const
|
|
111
|
+
const i = R(t, e, !0);
|
|
109
112
|
return new Promise((s) => {
|
|
110
|
-
n[r] = function(
|
|
111
|
-
if (r in window && delete n[r], a(
|
|
112
|
-
return
|
|
113
|
-
console.warn("response type check failed", t,
|
|
114
|
-
}, q(
|
|
113
|
+
n[r] = function(d) {
|
|
114
|
+
if (r in window && delete n[r], a(d))
|
|
115
|
+
return d;
|
|
116
|
+
console.warn("response type check failed", t, d), s(null);
|
|
117
|
+
}, q(i).catch(function() {
|
|
115
118
|
s(null), delete n[r];
|
|
116
119
|
});
|
|
117
120
|
});
|
|
118
121
|
}
|
|
119
|
-
async function
|
|
122
|
+
async function P(t, a, e = {}) {
|
|
120
123
|
const n = window;
|
|
121
|
-
return "var" in e || (e.var = "jsonxData" + Math.random().toString(16).slice(2)), t ? await q(
|
|
124
|
+
return "var" in e || (e.var = "jsonxData" + Math.random().toString(16).slice(2)), t ? await q(R(t, e, !0)).then(() => {
|
|
122
125
|
const r = n[e.var + ""];
|
|
123
126
|
return a(r) ? r : (console.warn("response type check failed", t, r), null);
|
|
124
127
|
}).catch(() => null) : null;
|
|
125
128
|
}
|
|
126
|
-
const
|
|
127
|
-
return await
|
|
129
|
+
const A = async function(t, a, e) {
|
|
130
|
+
return await k(t, a, e, {
|
|
128
131
|
baseURL: c.getConfig("baseURL"),
|
|
129
132
|
logHandler: c.getConfig("logHandler"),
|
|
130
133
|
errorHandler: c.getConfig("errorHandler"),
|
|
@@ -133,25 +136,25 @@ const P = async function(t, a, e) {
|
|
|
133
136
|
responseHandler: c.getConfig("responseHandler")
|
|
134
137
|
});
|
|
135
138
|
};
|
|
136
|
-
function
|
|
139
|
+
function U(t) {
|
|
137
140
|
if (!E.window)
|
|
138
141
|
throw new Error("Default Module Only Support In Browser");
|
|
139
|
-
return E.fetch ? new H(
|
|
142
|
+
return E.fetch ? new H(L, t) : new H(j, t);
|
|
140
143
|
}
|
|
141
|
-
const c =
|
|
144
|
+
const c = U(), M = c.setConfig, N = c.request, B = c.head, X = c.get, F = c.post, G = c.del, I = c.put, $ = c.patch;
|
|
142
145
|
export {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
146
|
+
U as NetRequest,
|
|
147
|
+
m as RequestInternalError,
|
|
148
|
+
G as del,
|
|
149
|
+
X as get,
|
|
150
|
+
K as getResponseRulesDescription,
|
|
151
|
+
B as head,
|
|
152
|
+
O as jsonp,
|
|
153
|
+
P as jsonx,
|
|
154
|
+
$ as patch,
|
|
155
|
+
F as post,
|
|
156
|
+
I as put,
|
|
157
|
+
N as request,
|
|
158
|
+
M as setGlobalConfig,
|
|
159
|
+
A as upload
|
|
157
160
|
};
|
package/dist/node.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./retry-8pExkGke.cjs"),y=require("./request.fetch-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./retry-8pExkGke.cjs"),y=require("./request.fetch-hlpQxV81.cjs"),b=require("node:http"),g=require("node:https"),E=async function(r,a,c){return e.handleResponse(await e.retryRequest(w,r,a,c),r,a,c)},w=async function(r,a,c){const t=await e.convertOptions(r,a,c);if(!e.At(t.url))return{url:t.url,method:t.method,status:-1,statusText:e.RequestInternalError.URLFormatError,headers:{},body:""};const R=/^https:\/\//i.test(t.url)?g:b,u=new URL(t.url),i=t.params;i instanceof Object&&Object.keys(i).forEach(n=>u.searchParams.set(n,i[n]));const q=t.method==="HEAD";return new Promise(n=>{const d=R.request(u,{headers:t.headers,method:t.method,timeout:t.timeout>0?t.timeout:void 0},function(o){const m=[];o.on("data",h=>m.push(h)),o.on("end",()=>{const h=e.fromEntries(Object.entries(o.headers).map(([f,l])=>[f.toLowerCase(),Array.isArray(l)?l.join(","):l]));n({url:u.toString(),method:t.method,status:o.statusCode||-1,statusText:o.statusMessage||e.RequestInternalError.Unknown,headers:h,body:q||o.statusCode===204?"":Buffer.concat(m).toString("utf-8")})})});d.on("error",o=>{n({url:u.toString(),method:t.method,status:-1,statusText:e.RequestInternalError.NetworkError,body:"",rawError:o})}),d.on("timeout",()=>{n({url:u.toString(),method:t.method,status:-1,statusText:e.RequestInternalError.Timeout,body:""})}),t.body&&d.write(t.body),d.end()})};function p(r){return e.jt.fetch?new e.NetRequestHandler(y.fetchRequest,r):new e.NetRequestHandler(E,r)}const s=p(),j=s.setConfig,C=s.head,I=s.get,N=s.post,S=s.del,T=s.put,O=s.patch;exports.RequestInternalError=e.RequestInternalError;exports.getResponseRulesDescription=e.getResponseRulesDescription;exports.NetRequest=p;exports.del=S;exports.get=I;exports.head=C;exports.patch=O;exports.post=N;exports.put=T;exports.setGlobalConfig=j;
|
package/dist/node.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { h as b, r as q, c as w, A as g, a as d, f as E, N as f, j } from "./retry-_AqXIa5P.js";
|
|
2
2
|
import { d as J } from "./retry-_AqXIa5P.js";
|
|
3
|
-
import { f as x } from "./request.fetch-
|
|
3
|
+
import { f as x } from "./request.fetch-1poQOlEV.js";
|
|
4
4
|
import A from "node:http";
|
|
5
5
|
import C from "node:https";
|
|
6
6
|
const N = async function(o, a, u) {
|
|
@@ -1,15 +1,18 @@
|
|
|
1
|
-
import { h as
|
|
1
|
+
import { h as w, r as y, c as E, j as T, f as R, a as c } from "./retry-_AqXIa5P.js";
|
|
2
2
|
const x = async function(s, o, n) {
|
|
3
|
-
return
|
|
3
|
+
return w(await y(g, s, o, n), s, o, n);
|
|
4
4
|
}, g = async function(s, o, n) {
|
|
5
|
-
const t = await
|
|
6
|
-
|
|
7
|
-
const r =
|
|
5
|
+
const t = await E(s, o, n), i = new URL(t.url), u = t.params;
|
|
6
|
+
u instanceof Object && Object.keys(u).forEach((e) => i.searchParams.set(e, u[e]));
|
|
7
|
+
const r = T.AbortController ? new AbortController() : null;
|
|
8
8
|
function d() {
|
|
9
9
|
r && !r.signal.aborted && r.abort();
|
|
10
10
|
}
|
|
11
11
|
t.abort && t.abort.addEventListener("abort", d);
|
|
12
|
-
|
|
12
|
+
let b = !1;
|
|
13
|
+
const l = t.timeout > 0 ? setTimeout(function() {
|
|
14
|
+
b = !0, d();
|
|
15
|
+
}, t.timeout) : null, f = t.method === "HEAD";
|
|
13
16
|
return await fetch(i, {
|
|
14
17
|
method: t.method,
|
|
15
18
|
headers: Object.keys(t.headers).length > 0 ? new Headers(t.headers) : void 0,
|
|
@@ -24,21 +27,21 @@ const x = async function(s, o, n) {
|
|
|
24
27
|
status: e.status,
|
|
25
28
|
statusText: e.statusText,
|
|
26
29
|
headers: R([...e.headers.entries()])
|
|
27
|
-
},
|
|
28
|
-
return
|
|
30
|
+
}, h = f || e.status === 204 ? "" : await e.text().catch((m) => m);
|
|
31
|
+
return h instanceof Error ? { ...a, body: "", statusText: c.Unknown, rawError: h } : { ...a, body: h };
|
|
29
32
|
}).catch((e) => {
|
|
30
33
|
const a = r == null ? void 0 : r.signal.aborted;
|
|
31
34
|
return {
|
|
32
35
|
url: i.toString(),
|
|
33
36
|
method: t.method,
|
|
34
|
-
status: a ? 0 : -1,
|
|
37
|
+
status: a && !b ? 0 : -1,
|
|
35
38
|
// 设置为 0 可以防止自动重试的默认策略
|
|
36
|
-
statusText: a ?
|
|
39
|
+
statusText: b ? c.Timeout : a ? c.Aborted : c.NetworkError,
|
|
37
40
|
body: "",
|
|
38
41
|
rawError: e
|
|
39
42
|
};
|
|
40
43
|
}).finally(() => {
|
|
41
|
-
|
|
44
|
+
l !== null && clearTimeout(l), t.abort && t.abort.removeEventListener("abort", d);
|
|
42
45
|
});
|
|
43
46
|
};
|
|
44
47
|
export {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const s=require("./retry-8pExkGke.cjs"),E=async function(n,a,i){return s.handleResponse(await s.retryRequest(w,n,a,i),n,a,i)},w=async function(n,a,i){const t=await s.convertOptions(n,a,i),u=new URL(t.url),c=t.params;c instanceof Object&&Object.keys(c).forEach(e=>u.searchParams.set(e,c[e]));const r=s.jt.AbortController?new AbortController:null;function d(){r&&!r.signal.aborted&&r.abort()}t.abort&&t.abort.addEventListener("abort",d);let l=!1;const h=t.timeout>0?setTimeout(function(){l=!0,d()},t.timeout):null,f=t.method==="HEAD";return await fetch(u,{method:t.method,headers:Object.keys(t.headers).length>0?new Headers(t.headers):void 0,body:t.body,credentials:t.credentials,signal:r==null?void 0:r.signal,redirect:"follow"}).then(async e=>{const o={url:u.toString(),method:t.method,status:e.status,statusText:e.statusText,headers:s.fromEntries([...e.headers.entries()])},b=f||e.status===204?"":await e.text().catch(m=>m);return b instanceof Error?{...o,body:"",statusText:s.RequestInternalError.Unknown,rawError:b}:{...o,body:b}}).catch(e=>{const o=r==null?void 0:r.signal.aborted;return{url:u.toString(),method:t.method,status:o&&!l?0:-1,statusText:l?s.RequestInternalError.Timeout:o?s.RequestInternalError.Aborted:s.RequestInternalError.NetworkError,body:"",rawError:e}}).finally(()=>{h!==null&&clearTimeout(h),t.abort&&t.abort.removeEventListener("abort",d)})};exports.fetchRequest=E;
|
package/package.json
CHANGED
package/types/inc/type.d.ts
CHANGED
|
@@ -45,7 +45,7 @@ export interface IBaseRequestOptions {
|
|
|
45
45
|
}
|
|
46
46
|
/** 重试请求的配置参数,暂不支持全局配置 */
|
|
47
47
|
export interface IRetryRequestOptions {
|
|
48
|
-
/** 错误时重试的次数,不能超过 10
|
|
48
|
+
/** 错误时重试的次数,不能超过 10 次,默认不重试 */
|
|
49
49
|
maxRetry?: number;
|
|
50
50
|
/** 重试策略:默认 network,可选 status 或者指定特殊的 status 或自定义检查 */
|
|
51
51
|
retryResolve?: IRetryResolve;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const s=require("./retry-8pExkGke.cjs"),m=async function(a,n,i){return s.handleResponse(await s.retryRequest(w,a,n,i),a,n,i)},w=async function(a,n,i){const t=await s.convertOptions(a,n,i),c=new URL(t.url),u=t.params;u instanceof Object&&Object.keys(u).forEach(e=>c.searchParams.set(e,u[e]));const r=s.jt.AbortController?new AbortController:null;function d(){r&&!r.signal.aborted&&r.abort()}t.abort&&t.abort.addEventListener("abort",d);const h=t.timeout>0?setTimeout(d,t.timeout):null,l=t.method==="HEAD";return await fetch(c,{method:t.method,headers:Object.keys(t.headers).length>0?new Headers(t.headers):void 0,body:t.body,credentials:t.credentials,signal:r==null?void 0:r.signal,redirect:"follow"}).then(async e=>{const o={url:c.toString(),method:t.method,status:e.status,statusText:e.statusText,headers:s.fromEntries([...e.headers.entries()])},b=l||e.status===204?"":await e.text().catch(f=>f);return b instanceof Error?{...o,body:"",statusText:s.RequestInternalError.Unknown,rawError:b}:{...o,body:b}}).catch(e=>{const o=r==null?void 0:r.signal.aborted;return{url:c.toString(),method:t.method,status:o?0:-1,statusText:o?s.RequestInternalError.Aborted:s.RequestInternalError.NetworkError,body:"",rawError:e}}).finally(()=>{h!==null&&clearTimeout(h),t.abort&&t.abort.removeEventListener("abort",d)})};exports.fetchRequest=m;
|