diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ba7685..bf26360 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## Version 0.6.7 - 2026-09-14 + +- Fix error handling for TooManyRequests and Forbidden errors + ## Version 0.6.6 - 2026-04-22 - Get predictions with correct output format in `create_prediction` and `get_prediction` diff --git a/pyproject.toml b/pyproject.toml index ac79ce9..89421a0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "cradl" -version = "0.6.6" +version = "0.6.7" description = "Python SDK for Cradl" authors = [{ name = "Cradl", email = "hello@cradl.ai" }] readme = "README.md" diff --git a/src/cradl/response.py b/src/cradl/response.py index 3f7095f..0d19232 100644 --- a/src/cradl/response.py +++ b/src/cradl/response.py @@ -22,22 +22,21 @@ def decode_response(response, return_json=True): raise e except Exception as e: logger.error('Status code {} body:\n{}'.format(response.status_code, response.text)) + message = response.json().get('message', response.text) if response.status_code == 400: - message = response.json().get('message', response.text) raise BadRequest(message) - if response.status_code == 403 and 'Forbidden' in response.json().values(): + if response.status_code == 403 and 'Forbidden' in message: raise InvalidCredentialsException('Credentials provided are not valid.') if response.status_code == 404: - message = response.json().get('message', response.text) raise NotFound(message) - if response.status_code == 429 and 'Too Many Requests' in response.json().values(): + if response.status_code == 429 and 'Too Many Requests' in message: raise TooManyRequestsException('You have reached the limit of requests per second.') - if response.status_code == 429 and 'Limit Exceeded' in response.json().values(): + if response.status_code == 429 and 'Limit Exceeded' in message: raise LimitExceededException('You have reached the limit of total requests per month.') raise e