badmfck-api-server 4.0.93 → 4.0.96
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.
|
@@ -62,6 +62,7 @@ class MicroserviceClient extends BaseService_1.BaseService {
|
|
|
62
62
|
const ts = Date.now().toString();
|
|
63
63
|
const nonce = crypto_1.default.randomBytes(12).toString("hex");
|
|
64
64
|
const maxAttempts = 10;
|
|
65
|
+
const attemptTimeout = 1000;
|
|
65
66
|
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
|
66
67
|
const rawSecret = Buffer.from(this.options.securityKey, "base64");
|
|
67
68
|
const key = crypto_1.default.createHash("sha256").update(rawSecret).digest();
|
|
@@ -79,19 +80,16 @@ class MicroserviceClient extends BaseService_1.BaseService {
|
|
|
79
80
|
"x-microservice-ts": ts,
|
|
80
81
|
"x-microservice-nonce": nonce
|
|
81
82
|
};
|
|
82
|
-
console.log(`Microservice call attempt ${attempt}: Sending request to ${url} with id: ${req.id}, requestName: ${req.requestName}`);
|
|
83
83
|
const resp = await Http_1.Http.post(url, {
|
|
84
84
|
tag: tag.toString("base64"),
|
|
85
85
|
enc: encrypted.toString("base64")
|
|
86
86
|
}, { headers });
|
|
87
87
|
if (!resp.ok && resp.details?.network) {
|
|
88
|
-
console.log(`Network error on microservice call attempt ${attempt}:`, resp);
|
|
89
88
|
if (attempt < maxAttempts) {
|
|
90
89
|
console.log(`Retrying microservice call... (attempt ${attempt}/${maxAttempts})`);
|
|
91
|
-
await TimeframeService_1.TimeframeService.wait(
|
|
90
|
+
await TimeframeService_1.TimeframeService.wait(attemptTimeout * attempt);
|
|
92
91
|
continue;
|
|
93
92
|
}
|
|
94
|
-
console.log(`Microservice call failed after ${attempt} attempts due to network errors.`);
|
|
95
93
|
return { ...DefaultErrors_1.default.EXTERNAL_SERVICE_ERROR, details: "Network connection lost after multiple retries, attempts: " + attempt };
|
|
96
94
|
}
|
|
97
95
|
if (!resp.ok) {
|
|
@@ -104,15 +102,12 @@ class MicroserviceClient extends BaseService_1.BaseService {
|
|
|
104
102
|
const body = resp.data;
|
|
105
103
|
const isAccepted = body?.error?.code === DefaultErrors_1.default.ACCEPTED.code || body?.code === DefaultErrors_1.default.ACCEPTED.code;
|
|
106
104
|
if (isAccepted) {
|
|
107
|
-
console.log(`Microservice call accepted, polling for result... (attempt ${attempt}/${maxAttempts})`);
|
|
108
105
|
if (attempt < maxAttempts) {
|
|
109
|
-
await TimeframeService_1.TimeframeService.wait(
|
|
106
|
+
await TimeframeService_1.TimeframeService.wait(attemptTimeout * attempt);
|
|
110
107
|
continue;
|
|
111
108
|
}
|
|
112
|
-
console.log(`Microservice call timed out after ${attempt} attempts.`);
|
|
113
109
|
return { ...DefaultErrors_1.default.EXTERNAL_SERVICE_ERROR, details: "Microservice processing timeout, attempts: " + attempt };
|
|
114
110
|
}
|
|
115
|
-
console.log(`Microservice call completed with response:`, body);
|
|
116
111
|
return (body && typeof body === "object" && "error" in body) ? body.error : (body.data ?? null);
|
|
117
112
|
}
|
|
118
113
|
return { ...DefaultErrors_1.default.EXTERNAL_SERVICE_ERROR, details: "Unknown polling error" };
|