fix: catch aiohttp.ClientError in all API call functions (#29) #57

Merged
cal merged 1 commits from ai/paper-dynasty-discord-29 into next-release 2026-03-07 07:43:04 +00:00

View File

@ -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):