Add --debug flag for verbose logging
- Add LAST30DAYS_DEBUG env var / --debug flag - Log HTTP requests, responses, and errors - Show API error details when debug enabled - Helps diagnose API failures Usage: python3 last30days.py "topic" --debug Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
+10
-1
@@ -2,10 +2,17 @@
|
||||
|
||||
import json
|
||||
import re
|
||||
import sys
|
||||
from typing import Any, Dict, List, Optional
|
||||
|
||||
from . import http
|
||||
|
||||
|
||||
def _log_error(msg: str):
|
||||
"""Log error to stderr."""
|
||||
sys.stderr.write(f"[X ERROR] {msg}\n")
|
||||
sys.stderr.flush()
|
||||
|
||||
# xAI uses chat completions endpoint
|
||||
XAI_CHAT_URL = "https://api.x.ai/v1/chat/completions"
|
||||
|
||||
@@ -129,7 +136,9 @@ def parse_x_response(response: Dict[str, Any]) -> List[Dict[str, Any]]:
|
||||
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)
|
||||
_log_error(f"xAI API error: {err_msg}")
|
||||
if http.DEBUG:
|
||||
_log_error(f"Full error response: {json.dumps(response, indent=2)[:1000]}")
|
||||
return items
|
||||
|
||||
# Try to find the output text
|
||||
|
||||
Reference in New Issue
Block a user