summaryrefslogtreecommitdiff
path: root/services/api/src/trading_api/routers/portfolio.py
diff options
context:
space:
mode:
Diffstat (limited to 'services/api/src/trading_api/routers/portfolio.py')
-rw-r--r--services/api/src/trading_api/routers/portfolio.py11
1 files changed, 9 insertions, 2 deletions
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")