Skip to content

Commit

Permalink
fix(ihev2): increasing dr retries count + adding bad response retry
Browse files Browse the repository at this point in the history
Refs: #1667
Signed-off-by: Jonah Kaye <[email protected]>
  • Loading branch information
jonahkaye committed Jun 18, 2024
1 parent d38cf85 commit 2ac2825
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
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;

0 comments on commit 2ac2825

Please sign in to comment.