From 6e65b9406f12cb06a65dceae7e9650b9427f7cb8 Mon Sep 17 00:00:00 2001 From: SukkaW Date: Thu, 10 Oct 2024 16:48:32 +0800 Subject: [PATCH] Fix: bail out fetch retry on 404 --- Build/lib/fetch-retry.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/Build/lib/fetch-retry.ts b/Build/lib/fetch-retry.ts index 045e0e88..9ed4d79e 100644 --- a/Build/lib/fetch-retry.ts +++ b/Build/lib/fetch-retry.ts @@ -40,7 +40,8 @@ interface FetchRetryOpt { maxRetryAfter?: number, // onRetry?: (err: Error) => void, retryOnAborted?: boolean, - retryOnNon2xx?: boolean + retryOnNon2xx?: boolean, + retryOn404?: boolean } interface FetchWithRetry { @@ -55,7 +56,8 @@ const DEFAULT_OPT: Required = { factor: 6, maxRetryAfter: 20, retryOnAborted: false, - retryOnNon2xx: true + retryOnNon2xx: true, + retryOn404: false }; function createFetchRetry($fetch: typeof fetch): FetchWithRetry { @@ -119,7 +121,13 @@ function createFetchRetry($fetch: typeof fetch): FetchWithRetry { } } - console.log(picocolors.gray('[fetch fail]'), url, err); + console.log(picocolors.gray('[fetch fail]'), url, (err as any).name, err); + + // Do not retry on 404 + if (err instanceof ResponseError && err.res.status === 404) { + return bail(err) as never; + } + const newErr = new Error('Fetch failed'); newErr.cause = err; throw newErr;