Spaces:
Sleeping
Sleeping
Claude Code Claude Opus 4.6 commited on
Commit ·
e0a8870
1
Parent(s): 30a95a7
fix: Add error handling to analytics API functions
Browse files- Add try/except to get_analytics_stats_json()
- Add try/except to get_conversation_history_json()
- Prevents uncaught exceptions from crashing API endpoints
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
app.py
CHANGED
|
@@ -1260,14 +1260,22 @@ def get_analytics_stats_json() -> Dict[str, Any]:
|
|
| 1260 |
"""Get analytics stats as JSON for API"""
|
| 1261 |
if not ANALYTICS_AVAILABLE or analytics is None:
|
| 1262 |
return {"error": "Analytics not available"}
|
| 1263 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1264 |
|
| 1265 |
|
| 1266 |
def get_conversation_history_json(limit: int = 50) -> List[Dict[str, Any]]:
|
| 1267 |
"""Get conversation history as JSON for API"""
|
| 1268 |
if not ANALYTICS_AVAILABLE or analytics is None:
|
| 1269 |
return [{"error": "Analytics not available"}]
|
| 1270 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1271 |
|
| 1272 |
|
| 1273 |
# ========== Session Archive Functions ==========
|
|
|
|
| 1260 |
"""Get analytics stats as JSON for API"""
|
| 1261 |
if not ANALYTICS_AVAILABLE or analytics is None:
|
| 1262 |
return {"error": "Analytics not available"}
|
| 1263 |
+
try:
|
| 1264 |
+
return analytics.get_stats()
|
| 1265 |
+
except Exception as e:
|
| 1266 |
+
logger.error(f"[ANALYTICS_ERROR] get_stats failed: {e}")
|
| 1267 |
+
return {"error": str(e)}
|
| 1268 |
|
| 1269 |
|
| 1270 |
def get_conversation_history_json(limit: int = 50) -> List[Dict[str, Any]]:
|
| 1271 |
"""Get conversation history as JSON for API"""
|
| 1272 |
if not ANALYTICS_AVAILABLE or analytics is None:
|
| 1273 |
return [{"error": "Analytics not available"}]
|
| 1274 |
+
try:
|
| 1275 |
+
return analytics.get_conversation_history(limit)
|
| 1276 |
+
except Exception as e:
|
| 1277 |
+
logger.error(f"[ANALYTICS_ERROR] get_conversation_history failed: {e}")
|
| 1278 |
+
return [{"error": str(e)}]
|
| 1279 |
|
| 1280 |
|
| 1281 |
# ========== Session Archive Functions ==========
|