diff --git a/CHANGELOG.md b/CHANGELOG.md index f88fb240f..cea2eaa9e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## 4.26.1 + +- [#306] (https://github.com/cohere-ai/cohere-python/pull/306) + - AsyncClient: Fix correctly raising error on connection issues. + ## 4.26 - [#296] (https://github.com/cohere-ai/cohere-python/pull/301) diff --git a/cohere/client_async.py b/cohere/client_async.py index f95e944a7..56e9f2b43 100644 --- a/cohere/client_async.py +++ b/cohere/client_async.py @@ -113,11 +113,13 @@ async def _request( try: json_response = await response.json() - # `CohereAPIError.from_response()` will capture the http status code + # `CohereAPIError.from_aio_response()` will capture the http status code except jsonlib.decoder.JSONDecodeError: - raise CohereAPIError.from_response(response, message=f"Failed to decode json body: {await response.text()}") + raise CohereAPIError.from_aio_response( + response, message=f"Failed to decode json body: {await response.text()}" + ) except aiohttp.ClientPayloadError as e: - raise CohereAPIError.from_response( + raise CohereAPIError.from_aio_response( response, message=f"An unexpected error occurred while receiving the response: {e}" ) diff --git a/cohere/error.py b/cohere/error.py index 3681bd35d..18c1afe1a 100644 --- a/cohere/error.py +++ b/cohere/error.py @@ -29,6 +29,10 @@ def __init__(self, message: str = None, http_status: int = None, headers: Dict = def from_response(cls, response, message=None): return cls(message=message or response.text, http_status=response.status_code, headers=response.headers) + @classmethod + def from_aio_response(cls, response, message): + return cls(message=message, http_status=response.status, headers=response.headers) + def __repr__(self) -> str: return f"{self.__class__.__name__}(message={str(self)}, http_status={self.http_status})" diff --git a/pyproject.toml b/pyproject.toml index 8b1695d12..cf3f915a0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "cohere" -version = "4.26" +version = "4.26.1" description = "" authors = ["Cohere"] readme = "README.md"