Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
8 changes: 5 additions & 3 deletions cohere/client_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
)

Expand Down
4 changes: 4 additions & 0 deletions cohere/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -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})"

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "cohere"
version = "4.26"
version = "4.26.1"
description = ""
authors = ["Cohere"]
readme = "README.md"
Expand Down