From 3c48b644db19b9eac2b4b7c3fe165bcd12648049 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 --- cohere/compass/clients/compass.py | 2 +- cohere/compass/exceptions.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/cohere/compass/clients/compass.py b/cohere/compass/clients/compass.py index 43afaf3..c284ffe 100644 --- a/cohere/compass/clients/compass.py +++ b/cohere/compass/clients/compass.py @@ -740,7 +740,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..397a736 100644 --- a/cohere/compass/exceptions.py +++ b/cohere/compass/exceptions.py @@ -1,8 +1,10 @@ + 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)