Skip to content

Commit

Permalink
fix: #1 (credit: @opyate)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdcarr committed Nov 4, 2019
1 parent fc75074 commit 656ee80
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,24 +86,25 @@ function onFulfilled(res: AxiosResponse) {
return res;
}

// tslint:disable-next-line no-any
const values = (objOrArray: {[key: string]: any}) => {
return Object.keys(objOrArray).map((key: string) => objOrArray[key]);
};

function onError(err: AxiosError) {
const config = (err.config as RaxConfig).raxConfig || {};
config.currentRetryAttempt = config.currentRetryAttempt || 0;
config.retry =
config.retry === undefined || config.retry === null ? 3 : config.retry;
config.retryDelay = config.retryDelay || 100;
config.instance = config.instance || axios;
config.httpMethodsToRetry = config.httpMethodsToRetry || [
'GET',
'HEAD',
'PUT',
'OPTIONS',
'DELETE',
];
config.noResponseRetries =
config.noResponseRetries === undefined || config.noResponseRetries === null
? 2
: config.noResponseRetries;
config.httpMethodsToRetry = values(
config.httpMethodsToRetry || ['GET', 'HEAD', 'PUT', 'OPTIONS', 'DELETE']);
config.noResponseRetries = (config.noResponseRetries === undefined ||
config.noResponseRetries === null) ?
2 :
config.noResponseRetries;


// If this wasn't in the list of status codes where we want
// to automatically retry, return.
Expand All @@ -119,7 +120,8 @@ function onError(err: AxiosError) {
[429, 429],
[500, 599],
];
config.statusCodesToRetry = config.statusCodesToRetry || retryRanges;
config.statusCodesToRetry =
values(config.statusCodesToRetry || retryRanges).map(values);

// Put the config back into the err
(err.config as RaxConfig).raxConfig = config;
Expand Down

0 comments on commit 656ee80

Please sign in to comment.