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 ?? {