summaryrefslogtreecommitdiff
path: root/packages/core/src/utils/quotaErrorDetection.ts
diff options
context:
space:
mode:
authorBryan Morgan <[email protected]>2025-07-09 13:55:56 -0400
committerGitHub <[email protected]>2025-07-09 17:55:56 +0000
commit8a6509ffeba271a8e7ccb83066a9a31a5d72a647 (patch)
treee67893a06d291f074e69f7f14d4f22ccbe3a6550 /packages/core/src/utils/quotaErrorDetection.ts
parent01e756481f359a28aca0d5220f853daec8d25ed4 (diff)
Remove auto-execution on Flash in the event of a 429/Quota failover (#3662)
Co-authored-by: Jenna Inouye <[email protected]>
Diffstat (limited to 'packages/core/src/utils/quotaErrorDetection.ts')
-rw-r--r--packages/core/src/utils/quotaErrorDetection.ts53
1 files changed, 47 insertions, 6 deletions
diff --git a/packages/core/src/utils/quotaErrorDetection.ts b/packages/core/src/utils/quotaErrorDetection.ts
index ec77f5ee..a8e87a5d 100644
--- a/packages/core/src/utils/quotaErrorDetection.ts
+++ b/packages/core/src/utils/quotaErrorDetection.ts
@@ -41,14 +41,23 @@ export function isProQuotaExceededError(error: unknown): boolean {
// Check for Pro quota exceeded errors by looking for the specific pattern
// This will match patterns like:
// - "Quota exceeded for quota metric 'Gemini 2.5 Pro Requests'"
- // - "Quota exceeded for quota metric 'Gemini 1.5-preview Pro Requests'"
- // - "Quota exceeded for quota metric 'Gemini beta-3.0 Pro Requests'"
- // - "Quota exceeded for quota metric 'Gemini experimental-v2 Pro Requests'"
+ // - "Quota exceeded for quota metric 'Gemini 2.5-preview Pro Requests'"
// We use string methods instead of regex to avoid ReDoS vulnerabilities
- const checkMessage = (message: string): boolean =>
- message.includes("Quota exceeded for quota metric 'Gemini") &&
- message.includes("Pro Requests'");
+ const checkMessage = (message: string): boolean => {
+ console.log('[DEBUG] isProQuotaExceededError checking message:', message);
+ const result =
+ message.includes("Quota exceeded for quota metric 'Gemini") &&
+ message.includes("Pro Requests'");
+ console.log('[DEBUG] isProQuotaExceededError result:', result);
+ return result;
+ };
+
+ // Log the full error object to understand its structure
+ console.log(
+ '[DEBUG] isProQuotaExceededError - full error object:',
+ JSON.stringify(error, null, 2),
+ );
if (typeof error === 'string') {
return checkMessage(error);
@@ -62,6 +71,38 @@ export function isProQuotaExceededError(error: unknown): boolean {
return checkMessage(error.error.message);
}
+ // Check if it's a Gaxios error with response data
+ if (error && typeof error === 'object' && 'response' in error) {
+ const gaxiosError = error as {
+ response?: {
+ data?: unknown;
+ };
+ };
+ if (gaxiosError.response && gaxiosError.response.data) {
+ console.log(
+ '[DEBUG] isProQuotaExceededError - checking response data:',
+ gaxiosError.response.data,
+ );
+ if (typeof gaxiosError.response.data === 'string') {
+ return checkMessage(gaxiosError.response.data);
+ }
+ if (
+ typeof gaxiosError.response.data === 'object' &&
+ gaxiosError.response.data !== null &&
+ 'error' in gaxiosError.response.data
+ ) {
+ const errorData = gaxiosError.response.data as {
+ error?: { message?: string };
+ };
+ return checkMessage(errorData.error?.message || '');
+ }
+ }
+ }
+
+ console.log(
+ '[DEBUG] isProQuotaExceededError - no matching error format for:',
+ error,
+ );
return false;
}