diff --git a/src/lib/sentry/policy.ts b/src/lib/sentry/policy.ts index 4f0fb687..68fb98a2 100644 --- a/src/lib/sentry/policy.ts +++ b/src/lib/sentry/policy.ts @@ -191,6 +191,17 @@ function isTransientTrpcHtmlError(error: unknown): boolean { return message.includes("Unexpected token '<'") || message.includes(" { return fetch(request, options) } +async function fetchWithRetriableStatuses( + request: RequestInfo | URL, + options?: RequestInit +): Promise { + const response = await fetchWithBodyClone(request, options) + + if (retriableHttpStatuses.has(response.status)) { + throw new Error(`Server returned HTTP status ${response.status}`) + } + + return response +} + export const saferFetch = withRetries( { maxAttempts: 5, backoff: attempt => attempt ** 2 * 5, retryOn: isRetriableFetchError }, - fetchWithBodyClone + fetchWithRetriableStatuses )