Spaces:
Running
Running
fix: gracefully catch ArXiv HTTP 429 errors and fix export analysis endpoint parameter binding
Browse files- app/api/routes/analysis.py +2 -2
- app/services/arxiv_service.py +16 -13
app/api/routes/analysis.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
"""
|
| 2 |
Routes analyses K2 Think
|
| 3 |
"""
|
| 4 |
-
from fastapi import APIRouter, Depends, HTTPException, status, BackgroundTasks
|
| 5 |
from fastapi.responses import Response, FileResponse
|
| 6 |
from sqlalchemy.orm import Session
|
| 7 |
from app.dependencies import get_db, get_current_user
|
|
@@ -586,7 +586,7 @@ async def get_specific_analysis(
|
|
| 586 |
async def export_analysis(
|
| 587 |
analysis_id: str,
|
| 588 |
format: str,
|
| 589 |
-
request: dict, # Pass full context to avoid refetching for demo
|
| 590 |
current_user = Depends(get_current_user)
|
| 591 |
):
|
| 592 |
"""
|
|
|
|
| 1 |
"""
|
| 2 |
Routes analyses K2 Think
|
| 3 |
"""
|
| 4 |
+
from fastapi import APIRouter, Depends, HTTPException, status, BackgroundTasks, Body
|
| 5 |
from fastapi.responses import Response, FileResponse
|
| 6 |
from sqlalchemy.orm import Session
|
| 7 |
from app.dependencies import get_db, get_current_user
|
|
|
|
| 586 |
async def export_analysis(
|
| 587 |
analysis_id: str,
|
| 588 |
format: str,
|
| 589 |
+
request: dict = Body(...), # Pass full context to avoid refetching for demo
|
| 590 |
current_user = Depends(get_current_user)
|
| 591 |
):
|
| 592 |
"""
|
app/services/arxiv_service.py
CHANGED
|
@@ -29,19 +29,22 @@ class ArXivService:
|
|
| 29 |
)
|
| 30 |
|
| 31 |
results = []
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
return results
|
| 47 |
|
|
|
|
| 29 |
)
|
| 30 |
|
| 31 |
results = []
|
| 32 |
+
try:
|
| 33 |
+
for result in search.results():
|
| 34 |
+
try:
|
| 35 |
+
results.append({
|
| 36 |
+
"id": result.get_short_id(),
|
| 37 |
+
"title": result.title,
|
| 38 |
+
"authors": [author.name for author in result.authors],
|
| 39 |
+
"summary": result.summary,
|
| 40 |
+
"url": result.pdf_url,
|
| 41 |
+
"categories": result.categories,
|
| 42 |
+
"publication_date": result.published.strftime("%Y-%m-%d") if result.published else None
|
| 43 |
+
})
|
| 44 |
+
except Exception as e:
|
| 45 |
+
logger.error(f"Error fetching metadata for {result.title}: {e}")
|
| 46 |
+
except Exception as api_err:
|
| 47 |
+
logger.error(f"ArXiv API request failed (e.g., 429 Too Many Requests): {api_err}")
|
| 48 |
|
| 49 |
return results
|
| 50 |
|