feat!: configure default retryCondition to retry more

Configure the default retryCondition to retry by default on gateway
errors or rate limit errors

commit-id:a7faaa02
This commit is contained in:
Conicaw 2024-01-21 20:19:12 -06:00
parent 7eed25d80a
commit f3e70c73ca
No known key found for this signature in database
GPG key ID: 8DE10AC00159C418
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 { AXIOS_INSTANCE_TOKEN, HTTP_MODULE_ID, HTTP_MODULE_OPTIONS } from './http.constants';
import { HttpService } from './http.service'; import { HttpService } from './http.service';
import { isNetworkOrIdempotentRequestOrGatewayOrRateLimitError } from './http.util';
import type { import type {
HttpModuleAsyncOptions, HttpModuleAsyncOptions,
HttpModuleOptions, HttpModuleOptions,
@ -18,6 +19,7 @@ const createAxiosInstance = (config?: HttpModuleOptions) => {
axiosRetry(axiosInstance, { axiosRetry(axiosInstance, {
// Default exponential backoff // Default exponential backoff
retryDelay: exponentialDelay, retryDelay: exponentialDelay,
retryCondition: isNetworkOrIdempotentRequestOrGatewayOrRateLimitError,
onRetry(retryCount, error, requestConfig) { onRetry(retryCount, error, requestConfig) {
logger.warn( 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; return !!error.response && error.response.status >= 502 && error.response.status <= 504;
} }
export function isNetworkOrIdempotentRequestOrGatewayError(error: AxiosError): boolean { export function isRateLimitError(error: AxiosError): boolean {
return isNetworkOrIdempotentRequestError(error) || isGatewayError(error); return !!error.response && error.response.status === 429;
}
export function isNetworkOrIdempotentRequestOrGatewayOrRateLimitError(error: AxiosError): boolean {
return (
isNetworkOrIdempotentRequestError(error) || isGatewayError(error) || isRateLimitError(error)
);
} }