@autofleet/network 1.2.9-alpha-9 → 1.2.9-alpha-11
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 +36 -5
- package/package.json +2 -1
package/index.js
CHANGED
|
@@ -1,7 +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');
|
|
3
|
+
const Logger = require('@autofleet/logger');
|
|
5
4
|
const qs = require('qs');
|
|
6
5
|
const httpAdapter = require('axios/lib/adapters/http');
|
|
7
6
|
const merge = require('deepmerge');
|
|
@@ -29,6 +28,7 @@ const HTTPMethods = [
|
|
|
29
28
|
];
|
|
30
29
|
|
|
31
30
|
const defaultSettings = {
|
|
31
|
+
timeout: 10000,
|
|
32
32
|
headers: {
|
|
33
33
|
'X-AF-AUTH': 'ANYONE',
|
|
34
34
|
'X-IAF-ORIGIN-SERVICE': process.env.AF_SERVICE_NAME || null,
|
|
@@ -67,10 +67,10 @@ module.exports = class Network {
|
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
this.axios = axios.create(this.settings);
|
|
71
|
-
|
|
70
|
+
this.axios = settings.cache ? setup(this.settings) : axios.create(this.settings);
|
|
71
|
+
this.addRetry(settings);
|
|
72
72
|
this.buildClassHttpMethods();
|
|
73
|
-
|
|
73
|
+
this.addLogs();
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
addRetry(settings) {
|
|
@@ -81,6 +81,37 @@ module.exports = class Network {
|
|
|
81
81
|
});
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
+
addLogs() {
|
|
85
|
+
const logger = Logger();
|
|
86
|
+
this.axios.interceptors.request.use((request) => {
|
|
87
|
+
logger.info(`Start Request: [${request.method.toUpperCase()}] ${request.baseURL} ${request.url}`, {
|
|
88
|
+
headers: request.headers,
|
|
89
|
+
query: request.query,
|
|
90
|
+
body: request.body,
|
|
91
|
+
params: request.params,
|
|
92
|
+
});
|
|
93
|
+
return request;
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
this.axios.interceptors.response.use((response) => {
|
|
97
|
+
logger.info(`Finish Request: [${response.config.method.toUpperCase()} ${response.config.url}`);
|
|
98
|
+
return response;
|
|
99
|
+
}, (error) => {
|
|
100
|
+
if(error.request._currentRequest.reusedSocket && error.code === 'ECONNRESET') {
|
|
101
|
+
logger.error('test dor', {
|
|
102
|
+
req: error.request,
|
|
103
|
+
code: error.code,
|
|
104
|
+
})
|
|
105
|
+
}
|
|
106
|
+
logger.error('test dor', {
|
|
107
|
+
req: error.request,
|
|
108
|
+
code: error.code,
|
|
109
|
+
})
|
|
110
|
+
logger.error('Finish Request with error', { status: error.status, data: error.response && error.response.data });
|
|
111
|
+
throw error;
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
84
115
|
createBaseUrl() {
|
|
85
116
|
if (!this.settings.serviceUrl && !this.settings.serviceName) {
|
|
86
117
|
throw new Error('At least one of the settings Missing serviceUrl or serviceName');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@autofleet/network",
|
|
3
|
-
"version": "1.2.9-alpha-
|
|
3
|
+
"version": "1.2.9-alpha-11",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
"author": "Dor Shay",
|
|
12
12
|
"license": "ISC",
|
|
13
13
|
"dependencies": {
|
|
14
|
+
"@autofleet/logger": "^1.2.3",
|
|
14
15
|
"@autofleet/node-common": "^1.5.1",
|
|
15
16
|
"agentkeepalive": "^4.1.4",
|
|
16
17
|
"axios": "^0.21.1",
|