Skip to content

Commit a3d3d61

Browse files
check different types of API error when updating tasks and ask to retry if found any (#693)
1 parent 92495a2 commit a3d3d61

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

packages/corejs/src/tasks/index.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,27 @@ const RETRY_CONFIG = {
3131
retries: MAX_RETRY_ATTEMPTS,
3232
retryDelay: (retryCount: number) => axiosRetry.exponentialDelay(retryCount),
3333
// shouldResetTimeout: true,
34-
retryCondition: (error: AxiosError) => axiosRetry.isNetworkOrIdempotentRequestError(error) || error?.response?.status === 500,
34+
retryCondition: (error: AxiosError) => {
35+
// Check if the error response is in a range of server error status codes (5xx)
36+
const hasServerError = error.response && error.response.status >= 500 && error.response.status <= 599;
37+
38+
// Check if the error is a CORS error
39+
const isCorsError = /cors/i.test(error.message);
40+
41+
// Check if the error is a network or idempotent request error
42+
const isNetworkError = axiosRetry.isNetworkOrIdempotentRequestError(error);
43+
44+
// Add a custom check for specific error messages
45+
const isCustomNetworkError = error.message && error.message === 'Network Error';
46+
47+
// Check for other common conditions that you might want to retry
48+
const shouldRetry = hasServerError
49+
|| isCorsError
50+
|| isNetworkError
51+
|| isCustomNetworkError;
52+
53+
return shouldRetry;
54+
},
3555
};
3656

3757
/**

0 commit comments

Comments
 (0)