@vpmedia/simplify 1.25.0 → 1.26.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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @vpmedia/simplify
|
|
2
2
|
|
|
3
|
-
[](https://badge.fury.io/js/@vpmedia%2Fsimplify)
|
|
4
4
|
[](https://github.com/vpmedia/simplify/actions/workflows/ci.yml)
|
|
5
5
|
|
|
6
6
|
@vpmedia/simplify TBD
|
package/package.json
CHANGED
package/src/util/fetchRetry.js
CHANGED
|
@@ -33,11 +33,12 @@ export class FetchError extends Error {
|
|
|
33
33
|
* Fetch with retry.
|
|
34
34
|
* @param {string | URL | Request} resource - Fetch URL.
|
|
35
35
|
* @param {RequestInit} [fetchOptions] - Fetch options.
|
|
36
|
-
* @param {{delay?: number, numTries?: number, statusExcludes?: number[]}} [retryOptions] - Retry options.
|
|
36
|
+
* @param {{delay?: number, numTries?: number, statusExcludes?: number[], timeout?: number}} [retryOptions] - Retry options.
|
|
37
37
|
* @returns {Promise<Response>} Fetch result.
|
|
38
38
|
*/
|
|
39
39
|
export const fetchRetry = async (resource, fetchOptions, retryOptions) => {
|
|
40
40
|
retryOptions = retryOptions ?? {};
|
|
41
|
+
retryOptions.timeout = Math.max(retryOptions.timeout ?? 10000, 1000);
|
|
41
42
|
retryOptions.delay = Math.max(retryOptions.delay ?? 500, 1);
|
|
42
43
|
retryOptions.numTries = Math.max(retryOptions.numTries ?? 3, 1);
|
|
43
44
|
retryOptions.statusExcludes = retryOptions.statusExcludes ?? [
|
|
@@ -48,6 +49,9 @@ export const fetchRetry = async (resource, fetchOptions, retryOptions) => {
|
|
|
48
49
|
];
|
|
49
50
|
while (retryOptions.numTries > 0) {
|
|
50
51
|
logger.info('request', { resource, fetchOptions, retryOptions });
|
|
52
|
+
const controller = new AbortController();
|
|
53
|
+
const timeoutId = setTimeout(() => controller.abort(), retryOptions.timeout);
|
|
54
|
+
fetchOptions.signal = controller.signal;
|
|
51
55
|
try {
|
|
52
56
|
const response = await fetch(resource, fetchOptions);
|
|
53
57
|
if (!response.ok) {
|
|
@@ -76,6 +80,8 @@ export const fetchRetry = async (resource, fetchOptions, retryOptions) => {
|
|
|
76
80
|
}
|
|
77
81
|
await delayPromise(retryOptions.delay);
|
|
78
82
|
retryOptions.delay *= 2;
|
|
83
|
+
} finally {
|
|
84
|
+
clearTimeout(timeoutId);
|
|
79
85
|
}
|
|
80
86
|
}
|
|
81
87
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetchRetry.d.ts","sourceRoot":"","sources":["../../src/util/fetchRetry.js"],"names":[],"mappings":"AAYA,yBAA0B,CAAC,CAAC;AAE5B;IACE;;;;;;OAMG;IACH,qBALW,MAAM,YACN,MAAM,GAAG,GAAG,GAAG,OAAO,gBACtB,WAAW,YACX,QAAQ,EAQlB;IAHC,iCAAwB;IACxB,0BAAgC;IAChC,mBAAwB;CAE3B;AASM,qCALI,MAAM,GAAG,GAAG,GAAG,OAAO,iBACtB,WAAW,iBACX;IAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,cAAc,CAAC,EAAE,MAAM,EAAE,CAAA;CAAC,
|
|
1
|
+
{"version":3,"file":"fetchRetry.d.ts","sourceRoot":"","sources":["../../src/util/fetchRetry.js"],"names":[],"mappings":"AAYA,yBAA0B,CAAC,CAAC;AAE5B;IACE;;;;;;OAMG;IACH,qBALW,MAAM,YACN,MAAM,GAAG,GAAG,GAAG,OAAO,gBACtB,WAAW,YACX,QAAQ,EAQlB;IAHC,iCAAwB;IACxB,0BAAgC;IAChC,mBAAwB;CAE3B;AASM,qCALI,MAAM,GAAG,GAAG,GAAG,OAAO,iBACtB,WAAW,iBACX;IAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAC,GAC9E,OAAO,CAAC,QAAQ,CAAC,CAkD7B"}
|