Merge pull request #262 from furality/spr/main/a7faaa02
feat!: configure default retryCondition to retry more
This commit is contained in:
commit
b7ecf84ac0
2 changed files with 10 additions and 2 deletions
|
@ -6,6 +6,7 @@ import axiosRetry, { exponentialDelay } from 'axios-retry';
|
|||
|
||||
import { AXIOS_INSTANCE_TOKEN, HTTP_MODULE_ID, HTTP_MODULE_OPTIONS } from './http.constants';
|
||||
import { HttpService } from './http.service';
|
||||
import { isNetworkOrIdempotentRequestOrGatewayOrRateLimitError } from './http.util';
|
||||
import type {
|
||||
HttpModuleAsyncOptions,
|
||||
HttpModuleOptions,
|
||||
|
@ -18,6 +19,7 @@ const createAxiosInstance = (config?: HttpModuleOptions) => {
|
|||
axiosRetry(axiosInstance, {
|
||||
// Default exponential backoff
|
||||
retryDelay: exponentialDelay,
|
||||
retryCondition: isNetworkOrIdempotentRequestOrGatewayOrRateLimitError,
|
||||
onRetry(retryCount, error, requestConfig) {
|
||||
logger.warn(
|
||||
{
|
||||
|
|
|
@ -5,6 +5,12 @@ export function isGatewayError(error: AxiosError): boolean {
|
|||
return !!error.response && error.response.status >= 502 && error.response.status <= 504;
|
||||
}
|
||||
|
||||
export function isNetworkOrIdempotentRequestOrGatewayError(error: AxiosError): boolean {
|
||||
return isNetworkOrIdempotentRequestError(error) || isGatewayError(error);
|
||||
export function isRateLimitError(error: AxiosError): boolean {
|
||||
return !!error.response && error.response.status === 429;
|
||||
}
|
||||
|
||||
export function isNetworkOrIdempotentRequestOrGatewayOrRateLimitError(error: AxiosError): boolean {
|
||||
return (
|
||||
isNetworkOrIdempotentRequestError(error) || isGatewayError(error) || isRateLimitError(error)
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue