format file

This commit is contained in:
A.K.M. Adib
2026-03-18 14:59:12 -04:00
parent d62684908f
commit 73b4435d75
2 changed files with 12 additions and 11 deletions

View File

@@ -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

View File

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