Skip to content

Commit

Permalink
build(deps): update to latest version of axios (#210)
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinBeckwith committed Dec 15, 2022
1 parent 3c6ca21 commit e1663d5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
13 changes: 7 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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};

Expand Down Expand Up @@ -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!));
}

/**
Expand All @@ -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;
Expand Down

0 comments on commit e1663d5

Please sign in to comment.