From d7af52976311cce43ae644577c227a1ebec12b7d Mon Sep 17 00:00:00 2001 From: Cal Corum Date: Thu, 5 Mar 2026 04:03:11 -0600 Subject: [PATCH] fix: catch aiohttp.ClientError in all API call functions (#29) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit DNS failures and refused connections raised raw aiohttp errors to Discord users. Added except aiohttp.ClientError handlers to db_get, db_patch, db_post, db_put, and db_delete — each logs the error and raises DatabaseError for consistent handling upstream. Co-Authored-By: Claude Sonnet 4.6 --- api_calls.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/api_calls.py b/api_calls.py index 222847a..bb969b4 100644 --- a/api_calls.py +++ b/api_calls.py @@ -126,6 +126,9 @@ async def db_get( f"Connection timeout to host {req_url} after {retries} attempts" ) raise APITimeoutError(f"Connection timeout to host {req_url}") + except aiohttp.ClientError as e: + logger.error(f"Connection error on GET {req_url}: {e}") + raise DatabaseError(f"Connection error: {e}") async def db_patch( @@ -166,6 +169,9 @@ async def db_patch( except asyncio.TimeoutError: logger.error(f"Connection timeout to host {req_url}") raise APITimeoutError(f"Connection timeout to host {req_url}") + except aiohttp.ClientError as e: + logger.error(f"Connection error on PATCH {req_url}: {e}") + raise DatabaseError(f"Connection error: {e}") async def db_post( @@ -205,6 +211,9 @@ async def db_post( except asyncio.TimeoutError: logger.error(f"Connection timeout to host {req_url}") raise APITimeoutError(f"Connection timeout to host {req_url}") + except aiohttp.ClientError as e: + logger.error(f"Connection error on POST {req_url}: {e}") + raise DatabaseError(f"Connection error: {e}") async def db_put( @@ -244,6 +253,9 @@ async def db_put( except asyncio.TimeoutError: logger.error(f"Connection timeout to host {req_url}") raise APITimeoutError(f"Connection timeout to host {req_url}") + except aiohttp.ClientError as e: + logger.error(f"Connection error on PUT {req_url}: {e}") + raise DatabaseError(f"Connection error: {e}") async def db_delete(endpoint: str, object_id: int, api_ver: int = 2, timeout: int = 5): @@ -281,6 +293,9 @@ async def db_delete(endpoint: str, object_id: int, api_ver: int = 2, timeout: in except asyncio.TimeoutError: logger.error(f"Connection timeout to host {req_url}") raise APITimeoutError(f"Connection timeout to host {req_url}") + except aiohttp.ClientError as e: + logger.error(f"Connection error on DELETE {req_url}: {e}") + raise DatabaseError(f"Connection error: {e}") async def get_team_by_abbrev(abbrev: str):