@mimik/request-retry 2.0.7 → 2.0.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/README.md +0 -8
- package/index.js +3 -17
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -17,14 +17,6 @@ Make a request with retry.
|
|
|
17
17
|
|
|
18
18
|
- <code>Promise</code> Will throw an error generated by `getRichError` encapsulating an error generated by [request-promise](https://www.npmjs.com/package/request-promise) or a TimeoutError.
|
|
19
19
|
|
|
20
|
-
The following environment variable are being used:
|
|
21
|
-
|
|
22
|
-
| Env variable name | Description | Default | Comments |
|
|
23
|
-
| ----------------- | ----------- | ------- | -------- |
|
|
24
|
-
| SERVER_TYPE | type of the server instance that makes the call | generic | for defining the agent
|
|
25
|
-
| SERVER_VERSION |version of the server instance that makes the call | 1.0 | for defining the agent
|
|
26
|
-
| SERVER_ID | id of the server instance that makes the call | generic | for defining the agent
|
|
27
|
-
|
|
28
20
|
The following properties are added to the `options` object under the `retry` property:
|
|
29
21
|
- retries `{int}`: maximum number of retries independent to the retryStrategy. The default is `2`. If the value is less than `0` the value is set to `0`, and if the value is more that `15` the value is set to `15`,
|
|
30
22
|
- delay `{int}`: in millisecond delay between retries if there is no retryDelay strategy. The default is `1000 ms`. If the value is less than `20 ms` the value is set to `20 ms`, and if the value is more than `30000 ms` the value is set to `30000 ms`,
|
package/index.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
/* eslint no-process-env: "off" */
|
|
2
1
|
const Promise = require('bluebird');
|
|
3
2
|
const axios = require('axios');
|
|
4
3
|
|
|
5
4
|
const logger = require('@mimik/sumologic-winston-logger');
|
|
6
5
|
const { getRichError } = require('@mimik/response-helper');
|
|
7
|
-
const { getCorrelationId } = require('@mimik/request-helper');
|
|
6
|
+
const { getCorrelationId, getUserAgent } = require('@mimik/request-helper');
|
|
8
7
|
const {
|
|
9
8
|
validateOptions,
|
|
10
9
|
calculateDelay,
|
|
@@ -19,11 +18,6 @@ const DEFAULT_LOGLEVEL_RESPONSE = 'info';
|
|
|
19
18
|
const DEFAULT_LOGLEVEL_ERROR = 'warn';
|
|
20
19
|
const DEFAULT_LOGLEVEL_REQUEST = 'info';
|
|
21
20
|
|
|
22
|
-
const nodeDescription = `${process.release.name} ${process.version} ${process.release.lts}`;
|
|
23
|
-
const serverDescription = `mimik-${process.env.SERVER_TYPE || 'generic'}/${process.env.SERVER_VERSION || '1.0'}/${process.env.SERVER_ID || 'generic'}`;
|
|
24
|
-
const platformDescription = `${process.platform}; ${process.arch}`;
|
|
25
|
-
const userAgent = `${serverDescription} (${platformDescription}; ${nodeDescription})`;
|
|
26
|
-
|
|
27
21
|
Promise.config({ cancellation: true });
|
|
28
22
|
|
|
29
23
|
/**
|
|
@@ -44,14 +38,6 @@ Promise.config({ cancellation: true });
|
|
|
44
38
|
* @fulfil {object} - Response of the [axios](https://www.npmjs.com/package/axios) response with option `resolveWithFullResponse` set to true otherwise only `response.data` is returned.
|
|
45
39
|
* @throws {Promise} Will throw an error generated by `getRichError` encapsulating an error generated by [request-promise](https://www.npmjs.com/package/request-promise) or a TimeoutError.
|
|
46
40
|
*
|
|
47
|
-
* The following environment variable are being used:
|
|
48
|
-
*
|
|
49
|
-
* | Env variable name | Description | Default | Comments |
|
|
50
|
-
* | ----------------- | ----------- | ------- | -------- |
|
|
51
|
-
* | SERVER_TYPE | type of the server instance that makes the call | generic | for defining the agent
|
|
52
|
-
* | SERVER_VERSION |version of the server instance that makes the call | 1.0 | for defining the agent
|
|
53
|
-
* | SERVER_ID | id of the server instance that makes the call | generic | for defining the agent
|
|
54
|
-
*
|
|
55
41
|
* The following properties are added to the `options` object under the `retry` property:
|
|
56
42
|
* - retries `{int}`: maximum number of retries independent to the retryStrategy. The default is `2`. If the value is less than `0` the value is set to `0`, and if the value is more that `15` the value is set to `15`,
|
|
57
43
|
* - delay `{int}`: in millisecond delay between retries if there is no retryDelay strategy. The default is `1000 ms`. If the value is less than `20 ms` the value is set to `20 ms`, and if the value is more than `30000 ms` the value is set to `30000 ms`,
|
|
@@ -95,8 +81,8 @@ const rpRetry = (origOptions) => {
|
|
|
95
81
|
let nbRetries = 0;
|
|
96
82
|
let mainTimeout;
|
|
97
83
|
|
|
98
|
-
if (!options.headers) options.headers = { 'user-agent':
|
|
99
|
-
else if (!options.headers['user-agent']) options.headers['user-agent'] =
|
|
84
|
+
if (!options.headers) options.headers = { 'user-agent': getUserAgent() };
|
|
85
|
+
else if (!options.headers['user-agent']) options.headers['user-agent'] = getUserAgent();
|
|
100
86
|
options.cancelToken = source.token;
|
|
101
87
|
|
|
102
88
|
const retryProcess = (nbRetry) => rp(options)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mimik/request-retry",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.8",
|
|
4
4
|
"description": "Request retry wrapping axios",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"url": "https://bitbucket.org/mimiktech/request-retry"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@mimik/request-helper": "^1.7.
|
|
32
|
+
"@mimik/request-helper": "^1.7.5",
|
|
33
33
|
"@mimik/response-helper": "^2.6.1",
|
|
34
34
|
"@mimik/sumologic-winston-logger": "^1.6.8",
|
|
35
35
|
"axios": "0.27.2",
|