From ec11e8befc012242f3dc07c0bc99ef9e114d5f5d Mon Sep 17 00:00:00 2001 From: Ben Eagan Date: Wed, 11 Dec 2024 15:05:19 -0500 Subject: [PATCH] Propagate the 400 error codes Fix typechecking increment package version --- cohere/compass/clients/compass.py | 2 +- cohere/compass/exceptions.py | 3 ++- pyproject.toml | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/cohere/compass/clients/compass.py b/cohere/compass/clients/compass.py index e5cf54a..3577cc8 100644 --- a/cohere/compass/clients/compass.py +++ b/cohere/compass/clients/compass.py @@ -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( diff --git a/cohere/compass/exceptions.py b/cohere/compass/exceptions.py index d5401a2..351a73f 100644 --- a/cohere/compass/exceptions.py +++ b/cohere/compass/exceptions.py @@ -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) diff --git a/pyproject.toml b/pyproject.toml index af2a441..c548182 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "compass-sdk" -version = "0.9.1" +version = "0.9.2" authors = [] description = "Compass SDK" readme = "README.md"