diff --git a/easyverein/__init__.py b/easyverein/__init__.py index 6264f78..91ebae0 100644 --- a/easyverein/__init__.py +++ b/easyverein/__init__.py @@ -2,7 +2,7 @@ Middleware for FastAPI that supports authenticating users against Keycloak """ -__version__ = "0.2.0" +__version__ = "0.2.1" # Export EasyVerein API directly from .api import EasyvereinAPI # noqa: F401 diff --git a/easyverein/core/client.py b/easyverein/core/client.py index ce958cc..af2a70a 100644 --- a/easyverein/core/client.py +++ b/easyverein/core/client.py @@ -103,13 +103,23 @@ def _do_request( # noqa: PLR0913 if res.status_code == 429: retry_after = res.headers["Retry-After"] + + try: + retry_after = int(retry_after) + except ValueError: + self.logger.error( + "Unable to parse Retry-After header while handling 429 response code." + ) + self.logger.debug("Retry-After header: %s", retry_after) + retry_after = 0 + self.logger.warning( "Request returned status code 429, too many requests. Wait %d seconds", retry_after, ) raise EasyvereinAPITooManyRetriesException( - retry_after, f"Too many requests, please wait {retry_after} seconds and try again.", + retry_after=retry_after, ) if res.status_code == 404: diff --git a/easyverein/core/exceptions.py b/easyverein/core/exceptions.py index c980de4..40660bd 100644 --- a/easyverein/core/exceptions.py +++ b/easyverein/core/exceptions.py @@ -21,4 +21,10 @@ class EasyvereinAPITooManyRetriesException(EasyvereinAPIException): Exception if the API returns a 429 Too Many Requests error """ + def __init__(self, message, retry_after: int = 0): + # Call the base class constructor with the parameters it needs + super().__init__(message) + + self.retry_after = retry_after + retry_after = 0 diff --git a/pyproject.toml b/pyproject.toml index b81cca4..59df8bb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "python-easyverein" -version = "0.2.0" +version = "0.2.1" description = "Python library to interact with the EasyVerein API" authors = ["Daniel Herrmann "] readme = "README.md"