Merge pull request #262 from furality/spr/main/a7faaa02

feat!: configure default retryCondition to retry more
This commit is contained in:
ttshivers 2024-01-21 20:21:43 -06:00 committed by GitHub
commit b7ecf84ac0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 10 additions and 2 deletions

View file

@ -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(
{

View file

@ -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)
);
}