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
+19 -8
View File
@@ -133,14 +133,25 @@ def run_research(
if mock:
raw_xai = load_fixture("xai_sample.json")
else:
raw_xai = xai_x.search_x(
config["XAI_API_KEY"],
selected_models["xai"],
topic,
from_date,
to_date,
depth=depth,
)
try:
raw_xai = xai_x.search_x(
config["XAI_API_KEY"],
selected_models["xai"],
topic,
from_date,
to_date,
depth=depth,
)
except http.HTTPError as e:
if progress:
progress.show_error(f"X API failed: {e}")
raw_xai = {"error": str(e)}
x_error = f"API error: {e}"
except Exception as e:
if progress:
progress.show_error(f"X error: {e}")
raw_xai = {"error": str(e)}
x_error = f"{type(e).__name__}: {e}"
# Parse response
x_items = xai_x.parse_x_response(raw_xai)