Skip to content

Commit 05220bc

Browse files
authored
fix: AsyncAnthropic._make_status_error missing 529 and 413 cases (#1244)
PR #854 added the 529 -> OverloadedError and 413 -> RequestTooLargeError checks to the sync Anthropic client's _make_status_error, but the duplicate copy in AsyncAnthropic was missed. As a result, async users get InternalServerError for 529 (since 529 >= 500) and the base APIStatusError for 413, instead of the specific exception types. Also adds a parametrized parity test to guard against the two copies drifting again.
1 parent be3dd14 commit 05220bc

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

tests/test_client.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,22 @@ def _get_open_connections(client: Anthropic | AsyncAnthropic) -> int:
112112
return len(pool._requests)
113113

114114

115+
@pytest.mark.parametrize("status_code", [400, 401, 403, 404, 409, 413, 422, 429, 500, 503, 529])
116+
def test_make_status_error_sync_async_parity(status_code: int) -> None:
117+
# Anthropic._make_status_error and AsyncAnthropic._make_status_error are
118+
# separate manually-maintained copies; this guards against them drifting.
119+
sync_client = Anthropic(base_url=base_url, api_key=api_key, _strict_response_validation=True)
120+
async_client = AsyncAnthropic(base_url=base_url, api_key=api_key, _strict_response_validation=True)
121+
response = httpx.Response(status_code, request=httpx.Request("GET", "/"))
122+
123+
sync_err = sync_client._make_status_error("msg", body=None, response=response)
124+
async_err = async_client._make_status_error("msg", body=None, response=response)
125+
126+
assert type(sync_err) is type(async_err), (
127+
f"sync returned {type(sync_err).__name__}, async returned {type(async_err).__name__}"
128+
)
129+
130+
115131
class TestAnthropic:
116132
@pytest.mark.respx(base_url=base_url)
117133
def test_raw_response(self, respx_mock: MockRouter, client: Anthropic) -> None:

0 commit comments

Comments
 (0)