Improve error handling and data validation in client analytics: Update API to return empty analytics data instead of raising an error when no data is available. Enhance date formatting checks in analytics calculations and frontend chart rendering to ensure robustness against invalid date formats.
This commit is contained in:
parent
234daebef7
commit
955eddd817
2 changed files with 146 additions and 16 deletions
25
views_api.py
25
views_api.py
|
|
@ -70,13 +70,26 @@ async def api_get_client_analytics(
|
|||
time_range: str = Query("30d", regex="^(7d|30d|90d|1y|all)$"),
|
||||
) -> ClientAnalytics:
|
||||
"""Get client performance analytics and cost basis data"""
|
||||
analytics = await get_client_analytics(wallet.wallet.user, time_range)
|
||||
if not analytics:
|
||||
raise HTTPException(
|
||||
status_code=HTTPStatus.NOT_FOUND,
|
||||
detail="Analytics data not available"
|
||||
try:
|
||||
analytics = await get_client_analytics(wallet.wallet.user, time_range)
|
||||
if not analytics:
|
||||
# Return empty analytics data instead of error
|
||||
return ClientAnalytics(
|
||||
user_id=wallet.wallet.user,
|
||||
cost_basis_history=[],
|
||||
accumulation_timeline=[],
|
||||
transaction_frequency={}
|
||||
)
|
||||
return analytics
|
||||
except Exception as e:
|
||||
print(f"Analytics error: {e}")
|
||||
# Return empty analytics data as fallback
|
||||
return ClientAnalytics(
|
||||
user_id=wallet.wallet.user,
|
||||
cost_basis_history=[],
|
||||
accumulation_timeline=[],
|
||||
transaction_frequency={}
|
||||
)
|
||||
return analytics
|
||||
|
||||
|
||||
@satmachineclient_api_router.put("/api/v1/dashboard/settings")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue