Skip to content

Commit

Permalink
feat!: configure default retryCondition to retry more
Browse files Browse the repository at this point in the history
Configure the default retryCondition to retry by default on gateway
errors or rate limit errors

commit-id:a7faaa02
  • Loading branch information
ttshivers committed Jan 22, 2024
1 parent 7eed25d commit f3e70c7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 2 additions & 0 deletions lib/http.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -18,6 +19,7 @@ const createAxiosInstance = (config?: HttpModuleOptions) => {
axiosRetry(axiosInstance, {
// Default exponential backoff
retryDelay: exponentialDelay,
retryCondition: isNetworkOrIdempotentRequestOrGatewayOrRateLimitError,
onRetry(retryCount, error, requestConfig) {
logger.warn(
{
Expand Down
10 changes: 8 additions & 2 deletions lib/http.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
}

0 comments on commit f3e70c7

Please sign in to comment.