@resolution/atlassian-api-common 0.13.0 → 0.13.2
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.
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* An implementation of the shouldRetryOnError function that retries on network and internal errors.
|
|
3
3
|
*/
|
|
4
|
-
export declare function retryOnNetworkAndInternalErrors(error: Error, attemptNumber: number): boolean;
|
|
4
|
+
export declare function retryOnNetworkAndInternalErrors(error: Error, attemptNumber: number): Promise<boolean> | boolean;
|
|
@@ -2,18 +2,46 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.retryOnNetworkAndInternalErrors = void 0;
|
|
4
4
|
const ApiError_1 = require("./ApiError");
|
|
5
|
+
/**
|
|
6
|
+
* A helper async function that waits for a given amount of time and then returns true.
|
|
7
|
+
*/
|
|
8
|
+
function waitAndReturnTrue(ms) {
|
|
9
|
+
return new Promise((resolve) => setTimeout(() => resolve(true), ms));
|
|
10
|
+
}
|
|
11
|
+
const delayGrowStep = 100;
|
|
12
|
+
/**
|
|
13
|
+
* The range of the jitter multiplier, follows recommendation from Atlassian.
|
|
14
|
+
* @see https://developer.atlassian.com/cloud/jira/platform/rate-limiting/#response-handling-pseudo-code
|
|
15
|
+
*/
|
|
16
|
+
const jitterMultiplierRange = [0.7, 1.3];
|
|
5
17
|
/**
|
|
6
18
|
* An implementation of the shouldRetryOnError function that retries on network and internal errors.
|
|
7
19
|
*/
|
|
8
20
|
function retryOnNetworkAndInternalErrors(error, attemptNumber) {
|
|
9
|
-
if (!(error instanceof ApiError_1.ApiError)) {
|
|
21
|
+
if (!(error instanceof ApiError_1.ApiError) || attemptNumber >= 3) {
|
|
10
22
|
return false;
|
|
11
23
|
}
|
|
12
|
-
|
|
13
|
-
|
|
24
|
+
const delayMultiplier = 1 +
|
|
25
|
+
Math.random() * (jitterMultiplierRange[1] - jitterMultiplierRange[0]) +
|
|
26
|
+
jitterMultiplierRange[0];
|
|
27
|
+
const defaultDelayBeforeRetry = attemptNumber * delayGrowStep * delayMultiplier;
|
|
28
|
+
// Network error.
|
|
29
|
+
if (!error.response) {
|
|
30
|
+
return waitAndReturnTrue(defaultDelayBeforeRetry);
|
|
31
|
+
}
|
|
32
|
+
if (error.response.status === 429 ||
|
|
33
|
+
(error.response.status >= 500 && error.response.status < 600)) {
|
|
34
|
+
// Check Retry-After header according to Atlassian recommendations.
|
|
35
|
+
// See https://developer.atlassian.com/cloud/jira/platform/rate-limiting/#rate-limit-related-headers
|
|
36
|
+
if (error.response.headers["retry-after"]) {
|
|
37
|
+
const retryAfter = parseInt(error.response.headers["retry-after"], 10);
|
|
38
|
+
if (!isNaN(retryAfter)) {
|
|
39
|
+
return waitAndReturnTrue(retryAfter * 1000 * delayMultiplier);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return waitAndReturnTrue(defaultDelayBeforeRetry);
|
|
14
43
|
}
|
|
15
|
-
return
|
|
16
|
-
(error.response.status >= 500 && error.response.status < 600));
|
|
44
|
+
return false;
|
|
17
45
|
}
|
|
18
46
|
exports.retryOnNetworkAndInternalErrors = retryOnNetworkAndInternalErrors;
|
|
19
47
|
//# sourceMappingURL=retryOnNetworkAndInternalErrors.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retryOnNetworkAndInternalErrors.js","sourceRoot":"","sources":["../src/retryOnNetworkAndInternalErrors.ts"],"names":[],"mappings":";;;AAAA,yCAAsC;AAEtC;;GAEG;AACH,SAAgB,+BAA+B,CAC7C,KAAY,EACZ,aAAqB;IAErB,IAAI,CAAC,CAAC,KAAK,YAAY,mBAAQ,CAAC,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"retryOnNetworkAndInternalErrors.js","sourceRoot":"","sources":["../src/retryOnNetworkAndInternalErrors.ts"],"names":[],"mappings":";;;AAAA,yCAAsC;AAEtC;;GAEG;AACH,SAAS,iBAAiB,CAAC,E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CAAC,UAAU,CAAC,EAAE,CAAC;gBACvB,OAAO,iBAAiB,CAAC,UAAU,GAAG,IAAI,GAAG,eAAe,CAAC,CAAC;YAChE,CAAC;QACH,CAAC;QACD,OAAO,iBAAiB,CAAC,uBAAuB,CAAC,CAAC;IACpD,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AArCD,0EAqCC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@resolution/atlassian-api-common",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.2",
|
|
4
4
|
"description": "Shared code across different implementations of Atlassian API Clients.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -43,5 +43,5 @@
|
|
|
43
43
|
"publishConfig": {
|
|
44
44
|
"access": "public"
|
|
45
45
|
},
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "7fcfd1a5a87f4238a8e501a61dbac4503a97786d"
|
|
47
47
|
}
|