From 73b4435d75bb0e7d87c2ab317953075d505bded7 Mon Sep 17 00:00:00 2001 From: "A.K.M. Adib" Date: Wed, 18 Mar 2026 14:59:12 -0400 Subject: [PATCH] format file --- packages/core/src/utils/googleErrors.ts | 2 +- packages/core/src/utils/googleQuotaErrors.ts | 21 ++++++++++---------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/packages/core/src/utils/googleErrors.ts b/packages/core/src/utils/googleErrors.ts index 231ff7993d..3499affff6 100644 --- a/packages/core/src/utils/googleErrors.ts +++ b/packages/core/src/utils/googleErrors.ts @@ -234,7 +234,7 @@ export function parseGoogleApiError(error: unknown): GoogleApiError | null { } // Basic structural check before casting. // Since the proto definitions are loose, we primarily rely on @type presence. - + if (typeof detailObj['@type'] === 'string') { // We can just cast it; the consumer will have to switch on @type // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion diff --git a/packages/core/src/utils/googleQuotaErrors.ts b/packages/core/src/utils/googleQuotaErrors.ts index c523581279..078ec7118f 100644 --- a/packages/core/src/utils/googleQuotaErrors.ts +++ b/packages/core/src/utils/googleQuotaErrors.ts @@ -242,6 +242,17 @@ export function classifyGoogleError(error: unknown): unknown { ); } + // Centralized check for RESOURCE_EXHAUSTED errors + if ( + googleApiError?.status === 'RESOURCE_EXHAUSTED' && + (status === 429 || status === 499) + ) { + const errorMessage = + googleApiError?.message || + (error instanceof Error ? error.message : String(error)); + return new TerminalQuotaError(errorMessage, googleApiError); + } + if ( !googleApiError || (googleApiError.code !== 429 && googleApiError.code !== 499) || @@ -269,12 +280,6 @@ export function classifyGoogleError(error: unknown): unknown { // Fallback: If it is a 429 or 499 but doesn't have a specific "retry in" message, // assume it is a temporary rate limit and retry after 5 sec (same as DEFAULT_RETRY_OPTIONS). - // However, if the API explicitly returns RESOURCE_EXHAUSTED without details, - // it indicates a hard quota exhaustion rather than a transient rate limit. - if (googleApiError?.status === 'RESOURCE_EXHAUSTED') { - return new TerminalQuotaError(errorMessage, googleApiError); - } - return new RetryableQuotaError( errorMessage, googleApiError ?? { @@ -413,10 +418,6 @@ export function classifyGoogleError(error: unknown): unknown { googleApiError?.message || (error instanceof Error ? error.message : String(error)); - if (googleApiError?.status === 'RESOURCE_EXHAUSTED') { - return new TerminalQuotaError(errorMessage, googleApiError); - } - return new RetryableQuotaError( errorMessage, googleApiError ?? {