From ace8873ebd31d431939fbf90728b6df5d55e3e10 Mon Sep 17 00:00:00 2001 From: Daniel Bankhead Date: Tue, 9 Apr 2024 10:48:21 -0700 Subject: [PATCH] feat: Retry `408` by Default --- README.md | 2 +- src/common.ts | 2 +- src/retry.ts | 2 ++ test/test.retry.ts | 1 + 4 files changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e94a67ae..7cf8b6b8 100644 --- a/README.md +++ b/README.md @@ -132,7 +132,7 @@ interface GaxiosOptions = { httpMethodsToRetry?: string[]; // The HTTP response status codes that will automatically be retried. - // Defaults to: [[100, 199], [429, 429], [500, 599]] + // Defaults to: [[100, 199], [408, 408], [429, 429], [500, 599]] statusCodesToRetry?: number[][]; // Function to invoke when a retry attempt is made. diff --git a/src/common.ts b/src/common.ts index 38779874..d4a2678a 100644 --- a/src/common.ts +++ b/src/common.ts @@ -304,7 +304,7 @@ export interface RetryConfig { /** * The HTTP response status codes that will automatically be retried. - * Defaults to: [[100, 199], [429, 429], [500, 599]] + * Defaults to: [[100, 199], [408, 408], [429, 429], [500, 599]] */ statusCodesToRetry?: number[][]; diff --git a/src/retry.ts b/src/retry.ts index 7e7b3d61..28ad6d7e 100644 --- a/src/retry.ts +++ b/src/retry.ts @@ -42,9 +42,11 @@ export async function getRetryConfig(err: GaxiosError) { // 2xx - Do not retry (Success) // 3xx - Do not retry (Redirect) // 4xx - Do not retry (Client errors) + // 408 - Retry ("Request Timeout") // 429 - Retry ("Too Many Requests") // 5xx - Retry (Server errors) [100, 199], + [408, 408], [429, 429], [500, 599], ]; diff --git a/test/test.retry.ts b/test/test.retry.ts index 7fe9cf14..53a07737 100644 --- a/test/test.retry.ts +++ b/test/test.retry.ts @@ -51,6 +51,7 @@ describe('🛸 retry & exponential backoff', () => { } const expectedStatusCodes = [ [100, 199], + [408, 408], [429, 429], [500, 599], ];