@heliyos/heliyos-api-core 1.0.54 → 1.0.56
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/dist/app.js +5 -4
- package/dist/axios.js +32 -0
- package/package.json +2 -1
package/dist/app.js
CHANGED
|
@@ -56,10 +56,11 @@ const coreApp = (app, routes, options) => __awaiter(void 0, void 0, void 0, func
|
|
|
56
56
|
const PORT = process.env.PORT || 3030;
|
|
57
57
|
// Create HTTP server.
|
|
58
58
|
const server = http_1.default.createServer(newApp);
|
|
59
|
-
//
|
|
60
|
-
|
|
61
|
-
server.
|
|
62
|
-
server.
|
|
59
|
+
// Configure server timeouts to prevent ECONNRESET errors
|
|
60
|
+
// Keep-alive timeout must be longer than client's keep-alive
|
|
61
|
+
server.keepAliveTimeout = 65000; // 65 seconds (ALB default is 60s)
|
|
62
|
+
server.headersTimeout = 66000; // Must be higher than keepAliveTimeout
|
|
63
|
+
server.setTimeout(60000); // Request timeout: 60 seconds
|
|
63
64
|
// Initialize mongoose database connections
|
|
64
65
|
yield (0, mongoose_1.initializeDatabase)();
|
|
65
66
|
// Graceful shutdown handler
|
package/dist/axios.js
CHANGED
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.coreAxios = void 0;
|
|
7
7
|
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
const axios_retry_1 = __importDefault(require("axios-retry"));
|
|
8
9
|
const logger_1 = require("./logger");
|
|
9
10
|
const http_1 = __importDefault(require("http"));
|
|
10
11
|
const https_1 = __importDefault(require("https"));
|
|
@@ -87,6 +88,37 @@ const servers = {
|
|
|
87
88
|
// Export axios plain object to call some third party external calls
|
|
88
89
|
axios: axios_1.default,
|
|
89
90
|
};
|
|
91
|
+
// Configure retry logic for all axios instances
|
|
92
|
+
const retryConfig = {
|
|
93
|
+
retries: 3, // Number of retry attempts
|
|
94
|
+
retryDelay: (retryCount) => {
|
|
95
|
+
// Exponential backoff: 1s, 2s, 4s
|
|
96
|
+
return Math.pow(2, retryCount) * 1000;
|
|
97
|
+
},
|
|
98
|
+
retryCondition: (error) => {
|
|
99
|
+
var _a, _b;
|
|
100
|
+
// Retry on network errors, 5xx errors, and specifically 503 errors
|
|
101
|
+
const isNetworkError = axios_retry_1.default.isNetworkError(error);
|
|
102
|
+
const isRetryableError = axios_retry_1.default.isRetryableError(error);
|
|
103
|
+
const is503Error = ((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 503;
|
|
104
|
+
const isECONNRESET = error.code === 'ECONNRESET';
|
|
105
|
+
const isTimeout = error.code === 'ECONNABORTED' || error.code === 'ETIMEDOUT';
|
|
106
|
+
// Log retry attempts for debugging
|
|
107
|
+
if (isNetworkError || isRetryableError || is503Error || isECONNRESET || isTimeout) {
|
|
108
|
+
logger_1.logger.warn(`api-core:axios-retry:attempting-retry:error=${error.name}:${error.message}:code=${error.code}:status=${(_b = error.response) === null || _b === void 0 ? void 0 : _b.status}`);
|
|
109
|
+
}
|
|
110
|
+
return isNetworkError || isRetryableError || is503Error || isECONNRESET || isTimeout;
|
|
111
|
+
},
|
|
112
|
+
onRetry: (retryCount, error, requestConfig) => {
|
|
113
|
+
logger_1.logger.info(`api-core:axios-retry:retry-attempt=${retryCount}:url=${requestConfig.url}:method=${requestConfig.method}:error=${error.message}`);
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
// Apply retry configuration to all server instances
|
|
117
|
+
for (const server_name of Object.keys(servers)) {
|
|
118
|
+
if (server_name !== 'axios') { // Don't apply to the plain axios object
|
|
119
|
+
(0, axios_retry_1.default)(servers[server_name], retryConfig);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
90
122
|
// Apply error handler to response interceptors
|
|
91
123
|
for (const server_name of Object.keys(servers)) {
|
|
92
124
|
servers[server_name].interceptors.response.use((r) => r, handleAxiosError);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@heliyos/heliyos-api-core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.56",
|
|
4
4
|
"description": "Heliyos's core api functions and middlewares. Its a private package hosted on npm.",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
"@aws-sdk/client-secrets-manager": "3.682.0",
|
|
32
32
|
"@aws-sdk/client-sqs": "3.682.0",
|
|
33
33
|
"axios": "^1.7.7",
|
|
34
|
+
"axios-retry": "4.5.0",
|
|
34
35
|
"basic-auth": "^2.0.1",
|
|
35
36
|
"body-parser": "^1.20.3",
|
|
36
37
|
"compression": "1.8.1",
|