feat: attempt more error parsing (#14899)

This commit is contained in:
Adam Weidman
2025-12-10 11:14:07 -08:00
committed by GitHub
parent c8b688655c
commit 22e6af414a
4 changed files with 100 additions and 25 deletions
+9 -3
View File
@@ -89,9 +89,15 @@ export function classifyGoogleError(error: unknown): unknown {
return new ModelNotFoundError(message, status);
}
if (!googleApiError || googleApiError.code !== 429) {
if (
!googleApiError ||
googleApiError.code !== 429 ||
googleApiError.details.length === 0
) {
// Fallback: try to parse the error message for a retry delay
const errorMessage = error instanceof Error ? error.message : String(error);
const errorMessage =
googleApiError?.message ||
(error instanceof Error ? error.message : String(error));
const match = errorMessage.match(/Please retry in ([0-9.]+(?:ms|s))/);
if (match?.[1]) {
const retryDelaySeconds = parseDurationInSeconds(match[1]);
@@ -108,7 +114,7 @@ export function classifyGoogleError(error: unknown): unknown {
}
}
return error; // Not a 429 error we can handle.
return error; // Not a 429 error we can handle with structured details or a parsable retry message.
}
const quotaFailure = googleApiError.details.find(