From 8267d094d0f3e0fb47187f5c1bede327c96fe08b Mon Sep 17 00:00:00 2001 From: Alberto Gonzalez Date: Sat, 18 Nov 2023 12:31:39 +0000 Subject: [PATCH] fix: PR feedback --- .vscode/settings.json | 3 --- package.json | 2 +- src/index.ts | 10 +++++----- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index a4e8fd8..2f754e5 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,7 +5,4 @@ "source.fixAll.eslint": true } }, - "eslint.options": { - "overrideConfigFile": "./.eslintrc" - } } diff --git a/package.json b/package.json index f661eb8..04661ea 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/index.ts b/src/index.ts index 0818311..fdecc13 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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; @@ -108,7 +108,7 @@ 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; @@ -116,7 +116,7 @@ export function isIdempotentRequestError(error: AxiosError) { 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); } @@ -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;