diff --git a/impresso/client.py b/impresso/client.py index 5fa0b9c..de470b1 100644 --- a/impresso/client.py +++ b/impresso/client.py @@ -11,6 +11,7 @@ from impresso.api_client import AuthenticatedClient from impresso.client_base import ImpressoApiResourcesBase from impresso.config_file import DEFAULT_API_URL, ImpressoPyConfig +from impresso.util.error import handle_known_errors from impresso.util.token import get_jwt_status logger = logging.getLogger(__name__) @@ -28,6 +29,9 @@ def _is_localhost_netloc(netloc: str) -> bool: def _log_non_2xx(response: httpx.Response) -> None: if response.status_code >= 400: response.read() + + handle_known_errors(response.status_code, response.text) + logging.error( f"Received error response ({response.status_code}): {response.text}" ) diff --git a/impresso/util/error.py b/impresso/util/error.py index e55c47e..0c7ab47 100644 --- a/impresso/util/error.py +++ b/impresso/util/error.py @@ -2,6 +2,7 @@ from impresso.api_client.models.error import Error as ApiError from impresso.api_models import Error +import re IT = TypeVar("IT") @@ -25,3 +26,13 @@ def raise_for_error(result: ApiError | IT) -> IT: raise ImpressoError(error) else: return result + + +def handle_known_errors(status_code: int, response_text: str) -> None: + # Known firewall errors + match = re.search(r"Your support ID is: ([^\s<>]+)", response_text) + if match: + support_id = match.group(1) + raise ValueError( + f"Request rejected. Please contact Impresso team on info@impresso-project.ch quoting the ID: {support_id}." + ) diff --git a/pyproject.toml b/pyproject.toml index 3e0be2b..a2dd7d5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -22,7 +22,7 @@ packages = [ ] readme = "README.md" repository = "https://github.com/impresso/impresso-py" -version = "0.9.9" +version = "0.9.10" [tool.poetry.urls] Endpoint = "https://impresso-project.ch/public-api"