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
Owner

Summary

api_calls.py was catching asyncio.TimeoutError but not aiohttp.ClientError, so DNS failures and refused connections raised raw, unformatted exceptions visible to Discord users.

Added except aiohttp.ClientError as e handlers to all five API functions:

  • db_get — logs error, raises DatabaseError (no retry, since connection errors differ from transient timeouts)
  • db_patch — logs error, raises DatabaseError
  • db_post — logs error, raises DatabaseError
  • db_put — logs error, raises DatabaseError
  • db_delete — logs error, raises DatabaseError

Files Changed

  • api_calls.py — 15 lines added (3 per function × 5 functions)

Test Results

No test suite. Changes verified by reading back the modified file and reviewing git diff.

## Summary `api_calls.py` was catching `asyncio.TimeoutError` but not `aiohttp.ClientError`, so DNS failures and refused connections raised raw, unformatted exceptions visible to Discord users. Added `except aiohttp.ClientError as e` handlers to all five API functions: - `db_get` — logs error, raises `DatabaseError` (no retry, since connection errors differ from transient timeouts) - `db_patch` — logs error, raises `DatabaseError` - `db_post` — logs error, raises `DatabaseError` - `db_put` — logs error, raises `DatabaseError` - `db_delete` — logs error, raises `DatabaseError` ## Files Changed - `api_calls.py` — 15 lines added (3 per function × 5 functions) ## Test Results No test suite. Changes verified by reading back the modified file and reviewing `git diff`.
cal added 1 commit 2026-03-05 10:03:28 +00:00
fix: catch aiohttp.ClientError in all API call functions (#29)
All checks were successful
Build Docker Image / build (pull_request) Successful in 1m15s
85b7980d6e
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>
cal added the
ai-reviewing
label 2026-03-05 10:15:32 +00:00
cal reviewed 2026-03-05 10:16:44 +00:00
cal left a comment
Author
Owner

AI Code Review

Files Reviewed

  • api_calls.py (modified)

Findings

Correctness

  • Implementation matches the PR description exactly: except aiohttp.ClientError as e added to all five functions (db_get, db_patch, db_post, db_put, db_delete).
  • Exception ordering is correct — except asyncio.TimeoutError appears before except aiohttp.ClientError in all handlers. These two hierarchies don't overlap (asyncio.TimeoutError is not a subclass of aiohttp.ClientError), so ordering is safe.
  • For db_get, the new handler is correctly placed inside the retry loop, causing an immediate DatabaseError raise without retry — consistent with the PR's stated rationale that connection errors (DNS, refused connections) won't resolve within a retry window.
  • DatabaseError is the right exception type here — it's already raised for non-200 HTTP responses and is presumably caught/formatted by the cog layer before reaching Discord users.

Security

  • No issues. The {e} in the error message is from an aiohttp internal exception, logged server-side only and wrapped in DatabaseError — not directly exposed to Discord output.

Style & Conventions

  • Pattern is perfectly consistent with existing code (same log format, same raise pattern as the asyncio.TimeoutError handlers).

Suggestions

  • The db_get docstring's Raises section currently only documents APITimeoutError and DatabaseError (for non-200). The new DatabaseError for connection errors is a third raise path not documented. Minor gap, no blocker.

Verdict: APPROVED

Minimal, correct fix for a real bug. The implementation is consistent, the exception hierarchy is handled in the right order, and the no-retry decision for connection errors is sound. No blocking issues.


Automated review by Claude PR Reviewer

## AI Code Review ### Files Reviewed - `api_calls.py` (modified) ### Findings #### Correctness - Implementation matches the PR description exactly: `except aiohttp.ClientError as e` added to all five functions (`db_get`, `db_patch`, `db_post`, `db_put`, `db_delete`). - Exception ordering is correct — `except asyncio.TimeoutError` appears before `except aiohttp.ClientError` in all handlers. These two hierarchies don't overlap (`asyncio.TimeoutError` is not a subclass of `aiohttp.ClientError`), so ordering is safe. - For `db_get`, the new handler is correctly placed inside the retry loop, causing an immediate `DatabaseError` raise without retry — consistent with the PR's stated rationale that connection errors (DNS, refused connections) won't resolve within a retry window. - `DatabaseError` is the right exception type here — it's already raised for non-200 HTTP responses and is presumably caught/formatted by the cog layer before reaching Discord users. #### Security - No issues. The `{e}` in the error message is from an aiohttp internal exception, logged server-side only and wrapped in `DatabaseError` — not directly exposed to Discord output. #### Style & Conventions - Pattern is perfectly consistent with existing code (same log format, same raise pattern as the `asyncio.TimeoutError` handlers). #### Suggestions - The `db_get` docstring's `Raises` section currently only documents `APITimeoutError` and `DatabaseError` (for non-200). The new `DatabaseError` for connection errors is a third raise path not documented. Minor gap, no blocker. ### Verdict: APPROVED Minimal, correct fix for a real bug. The implementation is consistent, the exception hierarchy is handled in the right order, and the no-retry decision for connection errors is sound. No blocking issues. --- *Automated review by Claude PR Reviewer*
cal added
ai-reviewed
and removed
ai-reviewing
labels 2026-03-05 10:16:52 +00:00
cal changed target branch from main to next-release 2026-03-07 07:32:30 +00:00
cal force-pushed ai/paper-dynasty-discord-29 from 85b7980d6e to d150e66bc7 2026-03-07 07:33:44 +00:00 Compare
cal merged commit 3131adaf76 into next-release 2026-03-07 07:43:04 +00:00
cal deleted branch ai/paper-dynasty-discord-29 2026-03-07 07:43:04 +00:00
Sign in to join this conversation.
No reviewers
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: cal/paper-dynasty-discord#57
No description provided.