From 16ef624551b60d2f06852d709b0c41bb6e000e81 Mon Sep 17 00:00:00 2001 From: MarkLo Date: Fri, 21 Nov 2025 12:06:32 +0800 Subject: [PATCH] --- backend/app/api/routes.py | 49 ++++++++++++++++++++++++++------------- backend/app/main.py | 3 ++- 2 files changed, 35 insertions(+), 17 deletions(-) diff --git a/backend/app/api/routes.py b/backend/app/api/routes.py index f9270074..5e9cabcb 100644 --- a/backend/app/api/routes.py +++ b/backend/app/api/routes.py @@ -52,22 +52,39 @@ async def run_analysis( Requires OpenAI API key to be provided in the request. """ - logger.info(f"Received analysis request for {request.ticker} on {request.analysis_date}") - - # Run analysis with all provided parameters including API keys - result = await service.run_analysis( - ticker=request.ticker, - analysis_date=request.analysis_date, - openai_api_key=request.openai_api_key, - openai_base_url=request.openai_base_url, - alpha_vantage_api_key=request.alpha_vantage_api_key, - analysts=request.analysts, - research_depth=request.research_depth, - deep_think_llm=request.deep_think_llm, - quick_think_llm=request.quick_think_llm, - ) - - return result + try: + logger.info(f"Received analysis request for {request.ticker} on {request.analysis_date}") + + # Run analysis with all provided parameters including API keys + result = await service.run_analysis( + ticker=request.ticker, + analysis_date=request.analysis_date, + openai_api_key=request.openai_api_key, + openai_base_url=request.openai_base_url, + alpha_vantage_api_key=request.alpha_vantage_api_key, + analysts=request.analysts, + research_depth=request.research_depth, + deep_think_llm=request.deep_think_llm, + quick_think_llm=request.quick_think_llm, + ) + + # Check if result contains error + if result.get("status") == "error": + logger.error(f"Analysis failed: {result.get('error')}") + raise HTTPException( + status_code=500, + detail=f"Analysis failed: {result.get('error', 'Unknown error')}" + ) + + return result + except HTTPException: + raise + except Exception as e: + logger.error(f"Unexpected error during analysis: {str(e)}", exc_info=True) + raise HTTPException( + status_code=500, + detail=f"Analysis failed: {str(e)}" + ) @router.get("/tickers") diff --git a/backend/app/main.py b/backend/app/main.py index e9c95a11..427c67e5 100644 --- a/backend/app/main.py +++ b/backend/app/main.py @@ -53,7 +53,8 @@ async def global_exception_handler(request, exc): status_code=500, content={ "error": "Internal server error", - "detail": str(exc) if settings.debug else "An unexpected error occurred", + "detail": str(exc), # Always return detailed error for user debugging + "type": type(exc).__name__, }, )