Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
opyate committed Feb 14, 2019
1 parent 317bd6a commit 5c992b8
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,20 @@ 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.httpMethodsToRetry = values(
config.httpMethodsToRetry || ['GET', 'HEAD', 'PUT', 'OPTIONS', 'DELETE']);
config.noResponseRetries = (config.noResponseRetries === undefined ||
config.noResponseRetries === null) ?
2 :
Expand All @@ -107,7 +112,8 @@ function onError(err: AxiosError) {
// 5xx - Retry (Server errors)
[100, 199], [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 5c992b8

Please sign in to comment.