fix(runtime-fallback): detect prettified quota errors without HTTP status codes (fixes #2747)

This commit is contained in:
MoerAI
2026-03-23 10:34:22 +09:00
parent 30dc50d880
commit 62d2704009
3 changed files with 102 additions and 1 deletions
@@ -21,6 +21,13 @@ export function getErrorMessage(error: unknown): string {
}
}
const errorObj2 = error as Record<string, unknown>
const name = errorObj2.name
if (typeof name === "string" && name.length > 0) {
const nameColonMatch = name.match(/:\s*(.+)/)
if (nameColonMatch) return nameColonMatch[1].trim().toLowerCase()
}
try {
return JSON.stringify(error).toLowerCase()
} catch {
@@ -112,6 +119,18 @@ export function classifyErrorType(error: unknown): string | undefined {
return "model_not_found"
}
if (
/quota.?exceeded/i.test(message) ||
/subscription.*quota/i.test(message) ||
/insufficient.?quota/i.test(message) ||
/billing.?(?:hard.?)?limit/i.test(message) ||
/exhausted\s+your\s+capacity/i.test(message) ||
/out\s+of\s+credits?/i.test(message) ||
/payment.?required/i.test(message)
) {
return "quota_exceeded"
}
return undefined
}
@@ -181,6 +200,10 @@ export function isRetryableError(error: unknown, retryOnErrors: number[]): boole
return true
}
if (errorType === "quota_exceeded") {
return true
}
if (statusCode && retryOnErrors.includes(statusCode)) {
return true
}