Add error handling for X/xAI API calls

- Wrap xAI search in try/except like Reddit
- Show error message but continue with Reddit results
- Parse function checks for API errors before processing

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Matt Van Horn
2026-01-23 16:50:05 -08:00
parent 546f93fe43
commit 9604d0ba46
2 changed files with 26 additions and 8 deletions
+7
View File
@@ -125,6 +125,13 @@ def parse_x_response(response: Dict[str, Any]) -> List[Dict[str, Any]]:
"""
items = []
# Check for API errors first
if "error" in response and response["error"]:
error = response["error"]
err_msg = error.get("message", str(error)) if isinstance(error, dict) else str(error)
print(f"[X ERROR] xAI API error: {err_msg}", flush=True)
return items
# Try to find the output text
output_text = ""
if "output" in response: