fix: catch aiohttp.ClientError in all API call functions (#29)
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 <noreply@anthropic.com>
This commit is contained in:
parent
4fcc8ed269
commit
d7af529763
15
api_calls.py
15
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):
|
||||
|
||||
Loading…
Reference in New Issue
Block a user