@autofleet/network 1.4.8-beta.0 → 1.4.9
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 +24 -6
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -38,7 +38,6 @@ const defaultSettings = {
|
|
|
38
38
|
shouldResetTimeout: true,
|
|
39
39
|
},
|
|
40
40
|
keepAlive: true,
|
|
41
|
-
enableHttpLogs: true,
|
|
42
41
|
};
|
|
43
42
|
|
|
44
43
|
const createRequestString = (request) => `[${(request.method || '').toUpperCase()}] ${request.baseURL}${request.url}`;
|
|
@@ -69,9 +68,7 @@ module.exports = class Network {
|
|
|
69
68
|
this.axios = settings.cache ? setup(this.settings) : axios.create(this.settings);
|
|
70
69
|
this.addRetry(settings);
|
|
71
70
|
this.buildClassHttpMethods();
|
|
72
|
-
|
|
73
|
-
this.addLogs();
|
|
74
|
-
}
|
|
71
|
+
this.addLogs();
|
|
75
72
|
}
|
|
76
73
|
|
|
77
74
|
addRetry(settings) {
|
|
@@ -99,11 +96,13 @@ module.exports = class Network {
|
|
|
99
96
|
return response;
|
|
100
97
|
}, (error) => {
|
|
101
98
|
if(error.request && error.request._currentRequest &&
|
|
102
|
-
error.request._currentRequest.reusedSocket &&
|
|
99
|
+
error.request._currentRequest.reusedSocket &&
|
|
100
|
+
['ECONNRESET', 'EPIPE'].includes(error.code)
|
|
101
|
+
) {
|
|
103
102
|
// See https://www.npmjs.com/package/agentkeepalive
|
|
104
103
|
// Support req.reusedSocket
|
|
105
104
|
// https://code-examples.net/en/q/28a8069
|
|
106
|
-
logger.warn(
|
|
105
|
+
logger.warn(`${error.code} issue, will retry`, {
|
|
107
106
|
req: error.request._currentRequest._currentUrl,
|
|
108
107
|
// method: error.request._currentRequest._options.method,
|
|
109
108
|
})
|
|
@@ -164,4 +163,23 @@ module.exports = class Network {
|
|
|
164
163
|
|
|
165
164
|
return currentResult;
|
|
166
165
|
}
|
|
166
|
+
|
|
167
|
+
async getAllPagesFromQueryEndpoint(url, options = {}) {
|
|
168
|
+
let currentResult = [];
|
|
169
|
+
|
|
170
|
+
let moreResultsToLoad = true;
|
|
171
|
+
let page = 1;
|
|
172
|
+
while(moreResultsToLoad && page < 100) {
|
|
173
|
+
const { data } = await this.post(url, {
|
|
174
|
+
...options,
|
|
175
|
+
page: page,
|
|
176
|
+
});
|
|
177
|
+
const { rows, count } = data;
|
|
178
|
+
page += 1;
|
|
179
|
+
currentResult = currentResult.concat(rows);
|
|
180
|
+
moreResultsToLoad = currentResult.length < count;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
return currentResult;
|
|
184
|
+
}
|
|
167
185
|
};
|