Update app/main.py
Browse files- app/main.py +12 -3
app/main.py
CHANGED
@@ -1201,9 +1201,18 @@ async def chat_completions(request: OpenAIRequest, api_key: str = Depends(get_ap
|
|
1201 |
# For non-streaming, if make_gemini_call doesn't raise, it's successful
|
1202 |
print(f"Attempt {i+1} ('{attempt['name']}') successful.")
|
1203 |
return result
|
1204 |
-
except Exception as e:
|
1205 |
-
|
1206 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1207 |
if i < len(attempts) - 1:
|
1208 |
print("Waiting 1 second before next attempt...")
|
1209 |
await asyncio.sleep(1) # Use asyncio.sleep for async context
|
|
|
1201 |
# For non-streaming, if make_gemini_call doesn't raise, it's successful
|
1202 |
print(f"Attempt {i+1} ('{attempt['name']}') successful.")
|
1203 |
return result
|
1204 |
+
except (Exception, ExceptionGroup) as e: # Catch ExceptionGroup as well
|
1205 |
+
actual_error = e
|
1206 |
+
if isinstance(e, ExceptionGroup):
|
1207 |
+
# Attempt to extract the first underlying exception if it's a group
|
1208 |
+
if e.exceptions:
|
1209 |
+
actual_error = e.exceptions[0]
|
1210 |
+
else:
|
1211 |
+
actual_error = ValueError("Empty ExceptionGroup caught") # Fallback
|
1212 |
+
|
1213 |
+
last_error = actual_error # Store the original or extracted error
|
1214 |
+
print(f"DEBUG: Caught exception in retry loop: type={type(e)}, potentially wrapped. Using: type={type(actual_error)}, value={repr(actual_error)}") # Updated debug log
|
1215 |
+
print(f"Attempt {i+1} ('{attempt['name']}') failed: {actual_error}") # Log the actual error
|
1216 |
if i < len(attempts) - 1:
|
1217 |
print("Waiting 1 second before next attempt...")
|
1218 |
await asyncio.sleep(1) # Use asyncio.sleep for async context
|