@mimik/request-retry 4.0.4 → 4.0.6
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 +2 -2
- package/index.js +4 -4
- package/lib/rp-axios-wrapper.js +2 -4
- package/manual-test/testEnv.js +1 -1
- package/manual-test/testRetry.js +2 -2
- package/package.json +8 -9
- package/test/testEnv.js +1 -1
package/README.md
CHANGED
|
@@ -17,7 +17,7 @@ Make a request with retries.
|
|
|
17
17
|
**Throws**:
|
|
18
18
|
|
|
19
19
|
- <code>Error</code> An error produced by `getRichError`, wrapping an error from
|
|
20
|
-
|
|
20
|
+
[request-promise](https://www.npmjs.com/package/request-promise) or a `TimeoutError`.
|
|
21
21
|
|
|
22
22
|
The following properties may be added to the `options` object under the `retry` property:
|
|
23
23
|
- retries `{int}`: Maximum number of retries, independent of the `retryStrategy`. Default: `2`.
|
|
@@ -71,5 +71,5 @@ To ease migration from `request-promise`, the following adjustments are applied
|
|
|
71
71
|
|
|
72
72
|
| Param | Type | Description |
|
|
73
73
|
| --- | --- | --- |
|
|
74
|
-
| options | <code>object</code> | Options for the request (similar to [axios](https://www.npmjs.com/package/axios)).
|
|
74
|
+
| options | <code>object</code> | Options for the request (similar to [axios](https://www.npmjs.com/package/axios)). The `validateStatus` option is disabled: an error is thrown for status codes outside **[200, 300)**. An additional option, `resolveWithFullResponse`, controls the return shape: when `true`, the full Axios response object is returned; when `false` or omitted, only `response.data` is returned. |
|
|
75
75
|
|
package/index.js
CHANGED
|
@@ -48,13 +48,13 @@ Promise.config({ cancellation: true });
|
|
|
48
48
|
* @requires @mimik/response-helper
|
|
49
49
|
* @category async
|
|
50
50
|
* @param {object} options - Options for the request (similar to [axios](https://www.npmjs.com/package/axios)).
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
51
|
+
* The `validateStatus` option is disabled: an error is thrown for status codes outside **[200, 300)**.
|
|
52
|
+
* An additional option, `resolveWithFullResponse`, controls the return shape:
|
|
53
|
+
* when `true`, the full Axios response object is returned; when `false` or omitted, only `response.data` is returned.
|
|
54
54
|
* @return {Promise}
|
|
55
55
|
* @fulfil {object} - The Axios response when `resolveWithFullResponse` is `true`; otherwise `response.data`.
|
|
56
56
|
* @throws {Error} An error produced by `getRichError`, wrapping an error from
|
|
57
|
-
*
|
|
57
|
+
* [request-promise](https://www.npmjs.com/package/request-promise) or a `TimeoutError`.
|
|
58
58
|
*
|
|
59
59
|
* The following properties may be added to the `options` object under the `retry` property:
|
|
60
60
|
* - retries `{int}`: Maximum number of retries, independent of the `retryStrategy`. Default: `2`.
|
package/lib/rp-axios-wrapper.js
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import axios from 'axios';
|
|
2
2
|
import { getRichError } from '@mimik/response-helper';
|
|
3
|
-
import rfdc from 'rfdc';
|
|
4
|
-
|
|
5
|
-
const clone = rfdc();
|
|
6
3
|
|
|
7
4
|
const rp = (origOptions) => {
|
|
8
|
-
const options =
|
|
5
|
+
const options = { ...origOptions }; // we will not do deep manipulation
|
|
9
6
|
|
|
7
|
+
if (options.metrics) delete options.metrics; // metrics has circular references
|
|
10
8
|
if (options.uri) options.url = options.uri;
|
|
11
9
|
delete options.uri;
|
|
12
10
|
delete options.validateStatus;
|
package/manual-test/testEnv.js
CHANGED
|
@@ -10,7 +10,7 @@ import process from 'process';
|
|
|
10
10
|
* | SUMO_LOGIC_COLLECTOR_CODE | code to use to log on sumologic | null
|
|
11
11
|
* | NO_STACK | flag to have a stack associated with the log | yes
|
|
12
12
|
* | LOG_LEVEL | log level to log | error
|
|
13
|
-
* | CONSOLE_LEVEL | log level to
|
|
13
|
+
* | CONSOLE_LEVEL | log level to display | debug
|
|
14
14
|
* | LOG_MODE | log mode | none
|
|
15
15
|
*/
|
|
16
16
|
/*
|
package/manual-test/testRetry.js
CHANGED
|
@@ -26,12 +26,12 @@ const options = {
|
|
|
26
26
|
* delayStrategy: 'joe', // => setDelay returning retryDelay
|
|
27
27
|
* delayStrategy: function badDelay() { return 'joe' }, // => no change then bad delay strategy => retryDelay
|
|
28
28
|
* delayStrategy: function userDelay(...args) { return (Math.pow(2, args[0]) * 100) + Math.floor(Math.random() * 50) }, // OK
|
|
29
|
-
* retryStrategy: 'joe', // =>
|
|
29
|
+
* retryStrategy: 'joe', // => unknownRetry returning false
|
|
30
30
|
* retryStrategy: function badRetry() { return 'joe' }, // => no change then bad retry strategy => false
|
|
31
31
|
* retryStrategy: function userRetry(...args) { // OK
|
|
32
32
|
* const { statusCode } = args[1]; // err
|
|
33
33
|
*
|
|
34
|
-
* return statusCode && (Math.floor(statusCode/100) !== 5 || statusCode !== 429); // retry if there is no statusCode or if there is 500 range
|
|
34
|
+
* return statusCode && (Math.floor(statusCode/100) !== 5 || statusCode !== 429); // retry if there is no statusCode or if there is 500 range statusCode or 429
|
|
35
35
|
* },
|
|
36
36
|
* retryStrategy: function invalidRetry(...args) { // defaultRetry
|
|
37
37
|
* const { statusCode } = args[34]; // null value
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mimik/request-retry",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.6",
|
|
4
4
|
"description": "Request retry wrapping axios",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -31,26 +31,25 @@
|
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@mimik/request-helper": "^2.0.2",
|
|
33
33
|
"@mimik/response-helper": "^4.0.6",
|
|
34
|
-
"@mimik/sumologic-winston-logger": "^2.1.
|
|
35
|
-
"axios": "1.12.
|
|
36
|
-
"bluebird": "3.7.2"
|
|
37
|
-
"rfdc": "1.4.1"
|
|
34
|
+
"@mimik/sumologic-winston-logger": "^2.1.8",
|
|
35
|
+
"axios": "1.12.2",
|
|
36
|
+
"bluebird": "3.7.2"
|
|
38
37
|
},
|
|
39
38
|
"devDependencies": {
|
|
40
|
-
"@eslint/js": "9.
|
|
39
|
+
"@eslint/js": "9.36.0",
|
|
41
40
|
"@mimik/eslint-plugin-document-env": "^2.0.8",
|
|
42
|
-
"@stylistic/eslint-plugin": "5.
|
|
41
|
+
"@stylistic/eslint-plugin": "5.4.0",
|
|
43
42
|
"acorn": "8.15.0",
|
|
44
43
|
"body-parser": "2.2.0",
|
|
45
44
|
"c8": "10.1.3",
|
|
46
45
|
"chai": "6.0.1",
|
|
47
|
-
"eslint": "9.
|
|
46
|
+
"eslint": "9.36.0",
|
|
48
47
|
"eslint-plugin-import": "2.32.0",
|
|
49
48
|
"express": "5.1.0",
|
|
50
49
|
"husky": "9.1.7",
|
|
51
50
|
"jsdoc-to-markdown": "9.1.2",
|
|
52
51
|
"mocha": "11.7.2",
|
|
53
|
-
"mochawesome": "7.1.
|
|
52
|
+
"mochawesome": "7.1.4",
|
|
54
53
|
"sinon": "21.0.0"
|
|
55
54
|
}
|
|
56
55
|
}
|
package/test/testEnv.js
CHANGED
|
@@ -10,7 +10,7 @@ import process from 'node:process';
|
|
|
10
10
|
* | SUMO_LOGIC_COLLECTOR_CODE | code to use to log on sumologic | null
|
|
11
11
|
* | NO_STACK | flag to have a stack associated with the log | yes
|
|
12
12
|
* | LOG_LEVEL | log level to log | error
|
|
13
|
-
* | CONSOLE_LEVEL | log level to
|
|
13
|
+
* | CONSOLE_LEVEL | log level to display | debug
|
|
14
14
|
* | LOG_MODE | log mode | none
|
|
15
15
|
*/
|
|
16
16
|
|