axios-master
Advanced tools
+23
-12
@@ -32,2 +32,3 @@ "use strict"; | ||
| const makeRequest = () => __awaiter(void 0, void 0, void 0, function* () { | ||
| var _a; | ||
| try { | ||
@@ -49,6 +50,11 @@ const response = yield (0, axios_1.default)(config); | ||
| } | ||
| const isTimeout = axios_1.default.isAxiosError(error) && | ||
| (error.code === "ECONNABORTED" || error.code === "ETIMEDOUT"); | ||
| if (isTimeout) { | ||
| console.log("\x1b[31m", "⚠️ Request timed out."); | ||
| } | ||
| console.log("\x1b[35m", ": reject"); | ||
| console.log("\x1b[33m", `${masterConfig.name || config.url} => ${elapsedTime} s :`); | ||
| if (error instanceof axios_1.AxiosError && error.response) { | ||
| console.log(error.response.data); | ||
| console.log((_a = error.response) === null || _a === void 0 ? void 0 : _a.data); | ||
| } | ||
@@ -71,2 +77,4 @@ console.log("\x1b[35m", ": reject"); | ||
| catch (error) { | ||
| const isTimeout = axios_1.default.isAxiosError(error) && | ||
| (error.code === "ECONNABORTED" || error.code === "ETIMEDOUT"); | ||
| if (error instanceof axios_1.AxiosError && | ||
@@ -84,5 +92,5 @@ ((_a = masterConfig.shouldRetryStatus) === null || _a === void 0 ? void 0 : _a.includes((_b = error.response) === null || _b === void 0 ? void 0 : _b.status)) && | ||
| request: default_config, | ||
| response: retryResponse.data, | ||
| responseBody: retryResponse.data, | ||
| statusCode: retryResponse.status, | ||
| response: retryResponse.data || null, | ||
| responseBody: isTimeout ? error.code : retryResponse.data, | ||
| statusCode: retryResponse.status || null, | ||
| }); | ||
@@ -92,10 +100,13 @@ return retryResponse.data; | ||
| catch (retryError) { | ||
| const isTimeout = axios_1.default.isAxiosError(retryError) && | ||
| (retryError.code === "ECONNABORTED" || | ||
| retryError.code === "ETIMEDOUT"); | ||
| log("WARN", `Retry API -> ${masterConfig.name || config.url} failed`, { | ||
| time: parseFloat(((Date.now() - startTime) / 1000).toFixed(5)), | ||
| request: default_config, | ||
| response: retryError.response, | ||
| responseBody: retryError.response.data, | ||
| statusCode: retryError.status, | ||
| response: retryError.response || null, | ||
| responseBody: isTimeout ? retryError.code : retryError.response.data, | ||
| statusCode: retryError.status || null, | ||
| }); | ||
| return Promise.reject(retryError.response); | ||
| return Promise.reject(isTimeout ? retryError : retryError.response); | ||
| } | ||
@@ -107,7 +118,7 @@ } | ||
| request: default_config, | ||
| response: error.response, | ||
| responseBody: error.response.data, | ||
| statusCode: error.status, | ||
| response: error.response || null, | ||
| responseBody: isTimeout ? error.code : error.response.data, | ||
| statusCode: error.status || null, | ||
| }); | ||
| return Promise.reject(error.response); | ||
| return Promise.reject(isTimeout ? error : error.response); | ||
| } | ||
@@ -114,0 +125,0 @@ } |
+1
-1
| { | ||
| "name": "axios-master", | ||
| "version": "2.0.1", | ||
| "version": "2.0.2", | ||
| "description": "Axios wrapper for advanced response time logging, retries, and token refresh.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
11695
7.66%148
8.03%