@superutils/fetch 1.1.7 → 1.1.8
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.js +21 -29
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -28,27 +28,22 @@ var executeInterceptors_default = executeInterceptors;
|
|
|
28
28
|
import PromisE from "@superutils/promise";
|
|
29
29
|
import { isPositiveInteger } from "@superutils/core";
|
|
30
30
|
var getResponse = async (...[url, options = {}]) => {
|
|
31
|
+
const fetchFunc = globalThis.fetch;
|
|
32
|
+
if (!isPositiveInteger(options.retry)) return fetchFunc(url, options);
|
|
31
33
|
let attemptCount = 0;
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
(
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
};
|
|
44
|
-
if (!isPositiveInteger(options.retry)) return doFetch();
|
|
45
|
-
const response = PromisE.retry(doFetch, {
|
|
46
|
-
...options,
|
|
47
|
-
retryIf: async (res, count) => {
|
|
48
|
-
var _a;
|
|
49
|
-
return (res == null ? void 0 : res.ok) === false || await ((_a = options == null ? void 0 : options.retryIf) == null ? void 0 : _a.call(options, res, count)) === true;
|
|
34
|
+
const response = PromisE.retry(
|
|
35
|
+
() => {
|
|
36
|
+
attemptCount++;
|
|
37
|
+
return fetchFunc(url, options);
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
...options,
|
|
41
|
+
retryIf: async (res, count) => {
|
|
42
|
+
var _a;
|
|
43
|
+
return (res == null ? void 0 : res.ok) === false || await ((_a = options == null ? void 0 : options.retryIf) == null ? void 0 : _a.call(options, res, count)) === true;
|
|
44
|
+
}
|
|
50
45
|
}
|
|
51
|
-
|
|
46
|
+
).catch(
|
|
52
47
|
(err) => Promise.reject(
|
|
53
48
|
new Error(`Request failed after attempt #${attemptCount}`, {
|
|
54
49
|
cause: err
|
|
@@ -237,6 +232,7 @@ fetch.defaults = {
|
|
|
237
232
|
response: [],
|
|
238
233
|
result: []
|
|
239
234
|
},
|
|
235
|
+
/** Request timeout duration in milliseconds. Default: `0` */
|
|
240
236
|
timeout: 0
|
|
241
237
|
};
|
|
242
238
|
var fetch_default = fetch;
|
|
@@ -269,16 +265,12 @@ import PromisE4 from "@superutils/promise";
|
|
|
269
265
|
// src/post.ts
|
|
270
266
|
import { isFn as isFn3, isStr } from "@superutils/core";
|
|
271
267
|
function post(...[url = "", data, options = {}]) {
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
},
|
|
279
|
-
options
|
|
280
|
-
)
|
|
281
|
-
);
|
|
268
|
+
var _a;
|
|
269
|
+
(_a = options.method) != null ? _a : options.method = "post";
|
|
270
|
+
return fetch_default(url, {
|
|
271
|
+
...options,
|
|
272
|
+
body: isStr(data) ? data : JSON.stringify(isFn3(data) ? data() : data)
|
|
273
|
+
});
|
|
282
274
|
}
|
|
283
275
|
|
|
284
276
|
// src/postDeferred.ts
|
package/package.json
CHANGED