From 776376dda8005635c4c3365905ca7df857789fec Mon Sep 17 00:00:00 2001 From: TheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com> Date: Thu, 2 Apr 2026 15:46:18 +0900 Subject: refactor: specialize exception handling across all services --- services/api/src/trading_api/routers/portfolio.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'services/api/src/trading_api/routers/portfolio.py') diff --git a/services/api/src/trading_api/routers/portfolio.py b/services/api/src/trading_api/routers/portfolio.py index d76d85d..3907a86 100644 --- a/services/api/src/trading_api/routers/portfolio.py +++ b/services/api/src/trading_api/routers/portfolio.py @@ -5,6 +5,7 @@ import logging from fastapi import APIRouter, HTTPException, Request from shared.sa_models import PositionRow from sqlalchemy import select +from sqlalchemy.exc import OperationalError logger = logging.getLogger(__name__) @@ -29,8 +30,11 @@ async def get_positions(request: Request): } for r in rows ] + except OperationalError as exc: + logger.error("Database error fetching positions: %s", exc) + raise HTTPException(status_code=503, detail="Database unavailable") except Exception as exc: - logger.error("Failed to get positions: %s", exc) + logger.error("Failed to get positions: %s", exc, exc_info=True) raise HTTPException(status_code=500, detail="Failed to retrieve positions") @@ -49,6 +53,9 @@ async def get_snapshots(request: Request, days: int = 30): } for s in snapshots ] + except OperationalError as exc: + logger.error("Database error fetching snapshots: %s", exc) + raise HTTPException(status_code=503, detail="Database unavailable") except Exception as exc: - logger.error("Failed to get snapshots: %s", exc) + logger.error("Failed to get snapshots: %s", exc, exc_info=True) raise HTTPException(status_code=500, detail="Failed to retrieve snapshots") -- cgit v1.2.3