diff options
| author | TheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com> | 2026-04-02 15:46:18 +0900 |
|---|---|---|
| committer | TheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com> | 2026-04-02 15:46:18 +0900 |
| commit | 776376dda8005635c4c3365905ca7df857789fec (patch) | |
| tree | 09a8f134929007b58981e6c5e756c3f3b4d3cbda /services/data-collector/src/data_collector/main.py | |
| parent | 8da5fb843856bb6585c6753f44d422beaa4a8204 (diff) | |
refactor: specialize exception handling across all services
Diffstat (limited to 'services/data-collector/src/data_collector/main.py')
| -rw-r--r-- | services/data-collector/src/data_collector/main.py | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/services/data-collector/src/data_collector/main.py b/services/data-collector/src/data_collector/main.py index 171db52..8b9f301 100644 --- a/services/data-collector/src/data_collector/main.py +++ b/services/data-collector/src/data_collector/main.py @@ -2,6 +2,8 @@ import asyncio +import aiohttp + from shared.alpaca import AlpacaClient from shared.broker import RedisBroker from shared.db import Database @@ -46,8 +48,10 @@ async def fetch_latest_bars( volume=Decimal(str(bar["v"])), ) candles.append(candle) - except Exception as exc: - log.warning("fetch_bar_failed", symbol=symbol, error=str(exc)) + except (aiohttp.ClientError, ConnectionError, TimeoutError, asyncio.TimeoutError) as exc: + log.warning("fetch_bar_network_error", symbol=symbol, error=str(exc)) + except (ValueError, KeyError, TypeError) as exc: + log.warning("fetch_bar_parse_error", symbol=symbol, error=str(exc)) return candles @@ -94,7 +98,7 @@ async def run() -> None: # Check if market is open try: is_open = await alpaca.is_market_open() - except Exception: + except (aiohttp.ClientError, ConnectionError, TimeoutError, asyncio.TimeoutError): is_open = False if is_open: @@ -113,7 +117,7 @@ async def run() -> None: await asyncio.sleep(poll_interval) except Exception as exc: - log.error("fatal_error", error=str(exc)) + log.error("fatal_error", error=str(exc), exc_info=True) await notifier.send_error(str(exc), "data-collector") raise finally: |
