Skip to content

Commit

Permalink
build: upgrade to xo 0.58 (#250)
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinBeckwith committed Mar 8, 2024
1 parent c03bda7 commit c19e810
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"semantic-release": "^23.0.0",
"sinon": "^17.0.0",
"typescript": "~5.3.0",
"xo": "^0.56.0"
"xo": "^0.58.0"
},
"files": [
"build/src"
Expand Down
16 changes: 8 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export type RaxConfig = {
* @returns The id of the interceptor attached to the axios instance.
*/
export function attach(instance?: AxiosInstance) {
instance = instance || axios;
instance ||= axios;
return instance.interceptors.response.use(
onFulfilled,
async (error: AxiosError) => onError(instance!, error),
Expand All @@ -102,7 +102,7 @@ export function attach(instance?: AxiosInstance) {
* @param instance The axios instance using this interceptor.
*/
export function detach(interceptorId: number, instance?: AxiosInstance) {
instance = instance || axios;
instance ||= axios;
instance.interceptors.response.eject(interceptorId);
}

Expand Down Expand Up @@ -175,12 +175,12 @@ async function onError(instance: AxiosInstance, error: AxiosError) {
}

const config = getConfig(error) || {};
config.currentRetryAttempt = config.currentRetryAttempt || 0;
config.currentRetryAttempt ||= 0;
config.retry = typeof config.retry === 'number' ? config.retry : 3;
config.retryDelay =
typeof config.retryDelay === 'number' ? config.retryDelay : 100;
config.instance = config.instance || instance;
config.backoffType = config.backoffType || 'exponential';
config.instance ||= instance;
config.backoffType ||= 'exponential';
config.httpMethodsToRetry = normalizeArray(config.httpMethodsToRetry) || [
'GET',
'HEAD',
Expand Down Expand Up @@ -221,8 +221,8 @@ async function onError(instance: AxiosInstance, error: AxiosError) {
(axiosError.config as RaxConfig).raxConfig = {...config};

// Determine if we should retry the request
const shouldRetryFn = config.shouldRetry || shouldRetryRequest;
if (!shouldRetryFn(axiosError)) {
const shouldRetryFunction = config.shouldRetry || shouldRetryRequest;
if (!shouldRetryFunction(axiosError)) {
throw axiosError;
}

Expand Down Expand Up @@ -345,7 +345,7 @@ export function shouldRetryRequest(error: AxiosError) {
}

// If we are out of retry attempts, return
config.currentRetryAttempt = config.currentRetryAttempt || 0;
config.currentRetryAttempt ||= 0;
if (config.currentRetryAttempt >= config.retry!) {
return false;
}
Expand Down
10 changes: 5 additions & 5 deletions test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,8 @@ describe('retry-axios', () => {
ax.defaults.raxConfig = {
retry: 3,
instance: ax,
onRetryAttempt(evt) {
console.log(`attempt #${evt.config!.raxConfig?.currentRetryAttempt}`);
onRetryAttempt(event) {
console.log(`attempt #${event.config!.raxConfig?.currentRetryAttempt}`);
},
};
interceptorId = rax.attach(ax);
Expand Down Expand Up @@ -534,15 +534,15 @@ describe('retry-axios', () => {
interceptorId = rax.attach();
try {
// eslint-disable-next-line import/no-named-as-default-member
const src = axios.CancelToken.source();
const source = axios.CancelToken.source();
const cfg: rax.RaxConfig = {
url,
raxConfig: {retry: 2},
cancelToken: src.token,
cancelToken: source.token,
};
const request = axios(cfg);
setTimeout(() => {
src.cancel();
source.cancel();
}, 10);
await request;
throw new Error('The canceled request completed.');
Expand Down

0 comments on commit c19e810

Please sign in to comment.