@webex/internal-plugin-ediscovery 3.0.0-beta.8 → 3.0.0-bnr.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/src/retry.js CHANGED
@@ -1,24 +1,33 @@
1
1
  const retryErrors = [429, 502, 503, 504];
2
2
 
3
- async function requestWithRetries(ctx, func, args, retryCount = 0, retryIntervalInSeconds = 0, maxRetries = 3) {
3
+ async function requestWithRetries(
4
+ ctx,
5
+ func,
6
+ args,
7
+ retryCount = 0,
8
+ retryIntervalInSeconds = 0,
9
+ maxRetries = 3
10
+ ) {
4
11
  await timeout(retryIntervalInSeconds);
5
12
 
6
- return func.apply(ctx, args)
7
- .catch((reason) => {
8
- if (retryErrors.includes(reason.statusCode) && retryCount < maxRetries) {
9
- retryCount += 1;
10
- let retryIntervalInSeconds = (retryCount + 1) ** 2; // 4, 9 and 16 second delays as default
13
+ return func.apply(ctx, args).catch((reason) => {
14
+ if (retryErrors.includes(reason.statusCode) && retryCount < maxRetries) {
15
+ retryCount += 1;
16
+ // eslint-disable-next-line no-shadow
17
+ let retryIntervalInSeconds = (retryCount + 1) ** 2; // 4, 9 and 16 second delays as default
11
18
 
12
- if (reason.headers && reason.headers['retry-after']) {
13
- retryIntervalInSeconds = reason.headers['retry-after'];
14
- }
15
- console.error(`Request #${retryCount} error: ${reason.statusCode}. Attempting retry #${retryCount} in ${retryIntervalInSeconds} seconds`);
16
-
17
- return requestWithRetries(ctx, func, args, retryCount, retryIntervalInSeconds, maxRetries);
19
+ if (reason.headers && reason.headers['retry-after']) {
20
+ retryIntervalInSeconds = reason.headers['retry-after'];
18
21
  }
22
+ console.error(
23
+ `Request #${retryCount} error: ${reason.statusCode}. Attempting retry #${retryCount} in ${retryIntervalInSeconds} seconds`
24
+ );
25
+
26
+ return requestWithRetries(ctx, func, args, retryCount, retryIntervalInSeconds, maxRetries);
27
+ }
19
28
 
20
- return Promise.reject(reason);
21
- });
29
+ return Promise.reject(reason);
30
+ });
22
31
  }
23
32
 
24
33
  function timeout(sec) {