Skip to content

Commit

Permalink
check different types of API error when updating tasks and ask to ret…
Browse files Browse the repository at this point in the history
…ry if found any
  • Loading branch information
rohitsharma120582 committed Mar 19, 2024
1 parent 92495a2 commit 41afec9
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion packages/corejs/src/tasks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,27 @@ const RETRY_CONFIG = {
retries: MAX_RETRY_ATTEMPTS,
retryDelay: (retryCount: number) => axiosRetry.exponentialDelay(retryCount),
// shouldResetTimeout: true,
retryCondition: (error: AxiosError) => axiosRetry.isNetworkOrIdempotentRequestError(error) || error?.response?.status === 500,
retryCondition: (error: AxiosError) => {
// Check if the error response is in a range of server error status codes (5xx)
const hasServerError = error.response && error.response.status >= 500 && error.response.status <= 599;

// Check if the error is a CORS error
const isCorsError = /cors/i.test(error.message);

// Check if the error is a network or idempotent request error
const isNetworkError = axiosRetry.isNetworkOrIdempotentRequestError(error);

// Add a custom check for specific error messages
const isCustomNetworkError = error.message && error.message === 'Network Error';

// Check for other common conditions that you might want to retry
const shouldRetry = hasServerError
|| isCorsError
|| isNetworkError
|| isCustomNetworkError;

return shouldRetry;
},
};

/**
Expand Down

0 comments on commit 41afec9

Please sign in to comment.