Skip to content

Commit

Permalink
fix: PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
mindhells committed Nov 18, 2023
1 parent 806591f commit 8267d09
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
3 changes: 0 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,4 @@
"source.fixAll.eslint": true
}
},
"eslint.options": {
"overrideConfigFile": "./.eslintrc"
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"is-retry-allowed": "^2.2.0"
},
"peerDependencies": {
"axios": "^0 || ^1"
"axios": "0.x || 1.x"
},
"devDependencies": {
"@types/axios": "^0.14.0",
Expand Down
10 changes: 5 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,14 @@ export function isNetworkError(error) {
const SAFE_HTTP_METHODS = ['get', 'head', 'options'];
const IDEMPOTENT_HTTP_METHODS = SAFE_HTTP_METHODS.concat(['put', 'delete']);

export function isRetryableError(error: AxiosError) {
export function isRetryableError(error: AxiosError): boolean {
return (
error.code !== 'ECONNABORTED' &&
(!error.response || (error.response.status >= 500 && error.response.status <= 599))
);
}

export function isSafeRequestError(error: AxiosError) {
export function isSafeRequestError(error: AxiosError): boolean {
if (!error.config?.method) {
// Cannot determine if the request can be retried
return false;
Expand All @@ -108,15 +108,15 @@ export function isSafeRequestError(error: AxiosError) {
return isRetryableError(error) && SAFE_HTTP_METHODS.indexOf(error.config.method) !== -1;
}

export function isIdempotentRequestError(error: AxiosError) {
export function isIdempotentRequestError(error: AxiosError): boolean {
if (!error.config?.method) {
// Cannot determine if the request can be retried
return false;
}
return isRetryableError(error) && IDEMPOTENT_HTTP_METHODS.indexOf(error.config.method) !== -1;
}

export function isNetworkOrIdempotentRequestError(error: AxiosError) {
export function isNetworkOrIdempotentRequestError(error: AxiosError): boolean {
return isNetworkError(error) || isIdempotentRequestError(error);
}

Expand All @@ -128,7 +128,7 @@ export function exponentialDelay(
retryNumber = 0,
_error: AxiosError | undefined = undefined,
delayFactor = 100
) {
): number {
const delay = 2 ** retryNumber * delayFactor;
const randomSum = delay * 0.2 * Math.random(); // 0-20% of the delay
return delay + randomSum;
Expand Down

0 comments on commit 8267d09

Please sign in to comment.