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/data-collector/src/data_collector/main.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'services/data-collector') 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: -- cgit v1.2.3