Skip to content

Commit

Permalink
Propagate the 400 error codes (#61)
Browse files Browse the repository at this point in the history
### Description 
Provide error code in CompassClientError to differentiate 400s
  • Loading branch information
benrules3 authored Dec 11, 2024
1 parent 3a5d494 commit 3d2d21b
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cohere/compass/clients/compass.py
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,7 @@ def _send_request_with_retry():
raise CompassAuthError(message=str(e))
elif 400 <= e.response.status_code < 500:
error = f"Client error occurred: {e.response.text}"
raise CompassClientError(message=error)
raise CompassClientError(message=error, code=e.response.status_code)
else:
error = str(e) + " " + e.response.text
logger.error(
Expand Down
3 changes: 2 additions & 1 deletion cohere/compass/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
class CompassClientError(Exception):
"""Exception raised for all 4xx client errors in the Compass client."""

def __init__(self, message: str = "Client error occurred."):
def __init__(self, message: str = "Client error occurred.", code: int = 400):
self.message = message
self.code = code
super().__init__(self.message)


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 = "compass-sdk"
version = "0.9.1"
version = "0.9.2"
authors = []
description = "Compass SDK"
readme = "README.md"
Expand Down

0 comments on commit 3d2d21b

Please sign in to comment.