@nsshunt/stsfhirclient 2.0.16 → 2.0.18

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.
@@ -9199,7 +9199,8 @@ function createRetryAxiosClient(retryConfig) {
9199
9199
  ], maxRetryDurationMs = 1e4, onRetryAttempt, stsAxiosConfig } = retryConfig || {};
9200
9200
  const instance = axios.create();
9201
9201
  instance.interceptors.request.use((config) => {
9202
- config.metadata = {
9202
+ const retryConfig = config;
9203
+ if (!retryConfig.metadata) retryConfig.metadata = {
9203
9204
  startTime: Date.now(),
9204
9205
  __retryCount: 0
9205
9206
  };
@@ -9212,13 +9213,15 @@ function createRetryAxiosClient(retryConfig) {
9212
9213
  const elapsed = Date.now() - config.metadata.startTime;
9213
9214
  const method = config.method.toLowerCase();
9214
9215
  const status = error.response?.status;
9215
- const code = error.code;
9216
- const isRetryable = retryMethods.includes(method) && (retryErrorCodes.includes(code || "") || retryStatusCodes.includes(status || 0));
9217
- if (config.metadata.__retryCount < maxRetries && isRetryable && elapsed < maxRetryDurationMs) {
9216
+ const code = error.code ?? "";
9217
+ const isRetryableMethod = retryMethods.includes(method);
9218
+ const isRetryableStatus = retryStatusCodes.includes(status ?? 0);
9219
+ const isRetryableCode = retryErrorCodes.includes(code);
9220
+ if (isRetryableMethod && (isRetryableStatus || isRetryableCode) && config.metadata.__retryCount < maxRetries && elapsed < maxRetryDurationMs) {
9218
9221
  config.metadata.__retryCount += 1;
9219
- const jitteredDelay = getJitteredDelay(retryDelayMs * Math.pow(2, config.metadata.__retryCount - 1), retryJitterMs);
9220
- if (onRetryAttempt) onRetryAttempt(config.metadata.__retryCount, error, jitteredDelay);
9221
- await sleep(jitteredDelay);
9222
+ const delayMs = getJitteredDelay(retryDelayMs * Math.pow(2, config.metadata.__retryCount - 1), retryJitterMs);
9223
+ onRetryAttempt?.(config.metadata.__retryCount, error, delayMs);
9224
+ await sleep(delayMs);
9222
9225
  return instance(config);
9223
9226
  }
9224
9227
  return Promise.reject(error);
@@ -9274,6 +9277,7 @@ var FhirRESTClient = class {
9274
9277
  maxRetryDurationMs: 5e3,
9275
9278
  onRetryAttempt: (attempt, error, delayMs) => {
9276
9279
  this.LogWarning("#InvokeResourceAPI", `Retry #${attempt} after ${delayMs}ms due to ${error.code || error.response?.status}`);
9280
+ if (this.#options.onRetryAttempt) this.#options.onRetryAttempt(attempt, error, delayMs);
9277
9281
  }
9278
9282
  })(url, requestConfig.config);
9279
9283
  };
@@ -15450,6 +15454,6 @@ var FhirSocketClientIndividual = class extends FhirSocketClient {
15450
15454
  };
15451
15455
  };
15452
15456
  //#endregion
15453
- export { FhirRESTClient, FhirRouteError, FhirSocketClient, FhirSocketClientAllInOne, FhirSocketClientIndividual, GetAboveHierarchy, STSFhirValidator, fhirRT, fhirSP, fhirSPRefOnly, getBaseResource, isAbsoluteUrl, normalizeUri, splitUnderBase };
15457
+ export { FhirRESTClient, FhirRouteError, FhirSocketClient, FhirSocketClientAllInOne, FhirSocketClientIndividual, GetAboveHierarchy, STSFhirValidator, createRetryAxiosClient, fhirRT, fhirSP, fhirSPRefOnly, getBaseResource, isAbsoluteUrl, normalizeUri, splitUnderBase };
15454
15458
 
15455
15459
  //# sourceMappingURL=stsfhirclient.mjs.map