Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Back Merge #2293

Merged
merged 9 commits into from
Jun 19, 2024
Prev Previous commit
Next Next commit
fix(ihev2): increasing dr retries count + adding bad response retry
Refs: #1667
Signed-off-by: Jonah Kaye <[email protected]>
  • Loading branch information
jonahkaye committed Jun 18, 2024
commit 2ac2825a02164a873e1c3eda9bbe505284b2a8e9
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
OutboundDocumentQueryReq,
OutboundDocumentRetrievalReq,
} from "@metriport/ihe-gateway-sdk";
import { sleep } from "@metriport/shared";
import { makeLambdaClient } from "../../aws/lambda";
import { Config } from "../../../util/config";
import { processAsyncError } from "../../../util/error/shared";
Expand Down Expand Up @@ -108,9 +109,14 @@ export class IHEGatewayV2Async extends IHEGatewayV2 {
MAX_DOCUMENT_RETRIEVAL_REQUESTS_PER_INVOCATION
);

for (const chunk of requestChunks) {
for (let i = 0; i < requestChunks.length; i++) {
const chunk = requestChunks[i];
const params = { patientId, cxId, requestId, drRequestsGatewayV2: chunk };

if (i > 0) {
await sleep(1000);
}

// intentionally not waiting
lambdaClient
.invoke({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export function handleHttpErrorResponse({
gateway,
patientId: outboundRequest?.patientId,
patientMatch: null,
iheGatewayV2: true,
operationOutcome,
};
}
Expand Down Expand Up @@ -74,6 +75,7 @@ export function handlePatientErrorResponse({
gateway,
patientId: outboundRequest.patientId,
patientMatch: null,
iheGatewayV2: true,
operationOutcome,
};
return response;
Expand Down Expand Up @@ -108,6 +110,7 @@ export function handleSchemaErrorResponse({
gateway,
patientId: outboundRequest.patientId,
patientMatch: null,
iheGatewayV2: true,
operationOutcome,
};
return response;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,21 @@ export async function sendSignedXmlMtom({
},
httpsAgent: agent,
responseType: "arraybuffer",
maxBodyLength: Infinity,
maxContentLength: Infinity,
});
},
{
initialDelay: 3000,
maxAttempts: 3,
maxAttempts: 4,
//TODO: This introduces retry on timeout without needing to specify the http Code: https://github.com/metriport/metriport/pull/2285. Remove once PR is merged
httpCodesToRetry: ["ECONNREFUSED", "ECONNRESET", "ETIMEDOUT"],
httpCodesToRetry: [
"ECONNREFUSED",
"ECONNRESET",
"ETIMEDOUT",
"ECONNABORTED",
"ERR_BAD_RESPONSE",
],
}
);

Expand Down
4 changes: 3 additions & 1 deletion packages/shared/src/net/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { AxiosError } from "axios";
// https://nodejs.org/docs/latest-v18.x/api/errors.html#common-system-errors
export type NodeNetworkError = "ECONNREFUSED" | "ECONNRESET";

export type NodeResponseError = "ERR_BAD_RESPONSE";

export type AxiosNetworkError = typeof AxiosError.ETIMEDOUT | typeof AxiosError.ECONNABORTED;

export type NetworkError = NodeNetworkError | AxiosNetworkError;
export type NetworkError = NodeNetworkError | AxiosNetworkError | NodeResponseError;