diff --git a/package.json b/package.json index afb963c..5d9111e 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,7 @@ "@types/mocha": "^10.0.0", "@types/sinon": "^10.0.11", "@types/node": "^18.0.0", - "axios": "^0.27.0", + "axios": "^1.2.1", "c8": "^7.11.2", "gts": "^3.1.0", "js-green-licenses": "^3.0.1", diff --git a/src/index.ts b/src/index.ts index 691c0bb..5fd8972 100644 --- a/src/index.ts +++ b/src/index.ts @@ -159,12 +159,12 @@ function parseRetryAfter(header: string): number | undefined { return undefined; } -function onError(err: AxiosError) { - if (axios.isCancel(err)) { - return Promise.reject(err); +function onError(e: AxiosError) { + if (axios.isCancel(e)) { + return Promise.reject(e); } - const config = getConfig(err) || {}; + const config = getConfig(e) || {}; config.currentRetryAttempt = config.currentRetryAttempt || 0; config.retry = typeof config.retry === 'number' ? config.retry : 3; config.retryDelay = @@ -203,6 +203,7 @@ function onError(err: AxiosError) { normalizeArray(config.statusCodesToRetry) || retryRanges; // Put the config back into the err + const err = e as AxiosError; err.config = err.config || {}; // allow for wider range of errors (err.config as RaxConfig).raxConfig = {...config}; @@ -279,7 +280,7 @@ function onError(err: AxiosError) { return Promise.resolve() .then(() => onBackoffPromise) .then(() => onRetryAttemptPromise) - .then(() => config.instance!.request(err.config)); + .then(() => config.instance!.request(err.config!)); } /** @@ -304,7 +305,7 @@ export function shouldRetryRequest(err: AxiosError) { // Only retry with configured HttpMethods. if ( - !err.config.method || + !err.config?.method || config.httpMethodsToRetry!.indexOf(err.config.method.toUpperCase()) < 0 ) { return false;