diff --git a/src/gradient_labs/errors.py b/src/gradient_labs/errors.py index 6729d7d..7b7cefe 100644 --- a/src/gradient_labs/errors.py +++ b/src/gradient_labs/errors.py @@ -1,3 +1,5 @@ +from json import JSONDecodeError + class ResponseError(Exception): """ Exeception representing an unexpected HTTP response status from the API. @@ -7,7 +9,10 @@ def __init__(self, response): super().__init__() self.status_code = response.status_code - self.message = response.json().get("message") + try: + self.message = response.json().get("message") + except JSONDecodeError: + self.message = response.text def __str__(self): return f"HTTP {self.status_code}: {self.message}"