@autofleet/network 1.2.9-alpha2 → 1.3.1
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/index.js +18 -5
- package/package.json +3 -3
package/index.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
const axios = require('axios');
|
|
2
|
-
const http = require('http');
|
|
3
|
-
const https = require('https');
|
|
4
2
|
const axiosRetry = require('axios-retry');
|
|
5
|
-
const
|
|
3
|
+
const Logger = require('@autofleet/logger');
|
|
6
4
|
const qs = require('qs');
|
|
7
5
|
const httpAdapter = require('axios/lib/adapters/http');
|
|
8
6
|
const merge = require('deepmerge');
|
|
@@ -30,6 +28,7 @@ const HTTPMethods = [
|
|
|
30
28
|
];
|
|
31
29
|
|
|
32
30
|
const defaultSettings = {
|
|
31
|
+
timeout: 10000,
|
|
33
32
|
headers: {
|
|
34
33
|
'X-AF-AUTH': 'ANYONE',
|
|
35
34
|
'X-IAF-ORIGIN-SERVICE': process.env.AF_SERVICE_NAME || null,
|
|
@@ -45,8 +44,12 @@ module.exports = class Network {
|
|
|
45
44
|
constructor(settings = {}) {
|
|
46
45
|
this.settings = merge(defaultSettings, settings);
|
|
47
46
|
if (this.settings.keepAlive) {
|
|
48
|
-
const keepaliveAgent = new Agent(
|
|
49
|
-
|
|
47
|
+
const keepaliveAgent = new Agent({
|
|
48
|
+
maxSockets: 1000
|
|
49
|
+
});
|
|
50
|
+
const keepaliveHttpsAgent = new HttpsAgent({
|
|
51
|
+
maxSockets: 1000
|
|
52
|
+
});
|
|
50
53
|
this.settings.httpAgent = keepaliveAgent;
|
|
51
54
|
this.settings.httpsAgent = keepaliveHttpsAgent;
|
|
52
55
|
delete this.settings.keepAlive;
|
|
@@ -94,6 +97,16 @@ module.exports = class Network {
|
|
|
94
97
|
logger.info(`Finish Request: [${response.config.method.toUpperCase()} ${response.config.url}`);
|
|
95
98
|
return response;
|
|
96
99
|
}, (error) => {
|
|
100
|
+
if(error.request._currentRequest.reusedSocket && error.code === 'ECONNRESET') {
|
|
101
|
+
// See https://www.npmjs.com/package/agentkeepalive
|
|
102
|
+
// Support req.reusedSocket
|
|
103
|
+
// https://code-examples.net/en/q/28a8069
|
|
104
|
+
logger.warn('ECONNRESET issue, will retry', {
|
|
105
|
+
req: error.request._currentRequest._currentUrl,
|
|
106
|
+
method: error.request._currentRequest._options.method,
|
|
107
|
+
})
|
|
108
|
+
return axios.request(error.config);
|
|
109
|
+
}
|
|
97
110
|
logger.error('Finish Request with error', { status: error.status, data: error.response && error.response.data });
|
|
98
111
|
throw error;
|
|
99
112
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@autofleet/network",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"author": "Dor Shay",
|
|
12
12
|
"license": "ISC",
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@autofleet/
|
|
14
|
+
"@autofleet/logger": "^1.1.0",
|
|
15
15
|
"agentkeepalive": "^4.1.4",
|
|
16
16
|
"axios": "^0.21.1",
|
|
17
17
|
"axios-cache-adapter": "^2.7.3",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"qs": "^6.5.2"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"jest": "
|
|
24
|
+
"jest": "^27.0.6",
|
|
25
25
|
"nock": "^10.0.0"
|
|
26
26
|
}
|
|
27
27
|
}
|