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): move error to axios, chunk instead of for
Refs: #1667
Signed-off-by: Jonah Kaye <[email protected]>
  • Loading branch information
jonahkaye committed Jun 18, 2024
commit f5a0e85a67ce5041c58901fedb051a11f27e89c9
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,7 @@ export class IHEGatewayV2Async extends IHEGatewayV2 {
MAX_DOCUMENT_RETRIEVAL_REQUESTS_PER_INVOCATION
);

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

if (i > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,26 @@ import https from "https";
import { constants } from "crypto";
import axios from "axios";
import * as AWS from "aws-sdk";
import dayjs from "dayjs";
import duration from "dayjs/plugin/duration";
import { SamlCertsAndKeys } from "./security/types";
import { Config } from "../../../../util/config";
import { out } from "../../../../util/log";
import { MetriportError } from "../../../../util/error/metriport-error";
import { createMtomContentTypeAndPayload } from "../outbound/xca/mtom/builder";
import { executeWithNetworkRetries } from "@metriport/shared";

import {
parseMtomResponse,
getBoundaryFromMtomResponse,
MtomAttachments,
convertSoapResponseToMtomResponse,
} from "../outbound/xca/mtom/parser";

dayjs.extend(duration);

const { log } = out("Saml Client");
const timeout = 120000;
const httpTimeout = dayjs.duration({ seconds: 120 }).asMilliseconds();
const initialDelay = dayjs.duration({ seconds: 3 }).asMilliseconds();
const maxPayloadSize = Infinity;
let rejectUnauthorized = true;
let trustedStore: string | undefined = undefined;
Expand Down Expand Up @@ -85,7 +89,7 @@ export async function sendSignedXml({
const response = await executeWithNetworkRetries(
async () => {
return axios.post(url, signedXml, {
timeout: timeout,
timeout: httpTimeout,
headers: {
"Content-Type": "application/soap+xml;charset=UTF-8",
Accept: "application/soap+xml",
Expand All @@ -95,7 +99,7 @@ export async function sendSignedXml({
});
},
{
initialDelay: 3000,
initialDelay: initialDelay,
maxAttempts: 3,
//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"],
Expand Down Expand Up @@ -130,7 +134,7 @@ export async function sendSignedXmlMtom({
const response = await executeWithNetworkRetries(
async () => {
return axios.post(url, payload, {
timeout: timeout,
timeout: httpTimeout,
headers: {
"Accept-Encoding": "gzip, deflate",
"Content-Type": contentType,
Expand All @@ -143,7 +147,7 @@ export async function sendSignedXmlMtom({
});
},
{
initialDelay: 3000,
initialDelay: initialDelay,
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: [
Expand Down
9 changes: 5 additions & 4 deletions packages/shared/src/net/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ 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
| typeof AxiosError.ERR_BAD_RESPONSE;

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

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