Detect OpenAI "no credits" 429 as exhausted balance
A real API call returned 429 "You have no credits remaining" without the word "quota", so the UI wrongly said the AI was busy. Match quota, credit and billing wording; test uses the real message. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
3b72436119
commit
2f73520150
+3
-2
@@ -237,8 +237,9 @@ def map_api_error(error):
|
||||
if isinstance(error, openai.APITimeoutError):
|
||||
return AIError("Die KI hat zu lange gebraucht. Bitte versuche es gleich noch einmal.")
|
||||
if isinstance(error, openai.RateLimitError):
|
||||
code = getattr(error, "code", None) or ""
|
||||
if "quota" in str(code) or "quota" in str(error).lower():
|
||||
# Out of credit is also a 429; OpenAI words it as "quota", "credits" or "billing".
|
||||
details = f"{getattr(error, 'code', None) or ''} {error}".lower()
|
||||
if any(word in details for word in ("quota", "credit", "billing")):
|
||||
return AIError("Das OpenAI-Guthaben ist aufgebraucht. Bitte den Admin informieren.")
|
||||
return AIError("Die KI ist gerade ausgelastet (Rate-Limit). Bitte in einer Minute erneut versuchen.")
|
||||
if isinstance(error, (openai.AuthenticationError, openai.PermissionDeniedError)):
|
||||
|
||||
Reference in New Issue
Block a user