From 32dfe30a940b116cda6927d595c041a7dd1ec54e Mon Sep 17 00:00:00 2001 From: Roman Kalyakin Date: Thu, 24 Oct 2024 14:07:53 +0200 Subject: [PATCH 1/3] handle known firewall request rejected errors --- impresso/client.py | 4 ++++ impresso/util/error.py | 12 ++++++++++++ 2 files changed, 16 insertions(+) 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..ca23243 100644 --- a/impresso/util/error.py +++ b/impresso/util/error.py @@ -1,7 +1,9 @@ +from json import JSONDecodeError from typing import TypeVar from impresso.api_client.models.error import Error as ApiError from impresso.api_models import Error +import re IT = TypeVar("IT") @@ -25,3 +27,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}." + ) From 27450f938f75dee1bef553e25d6ddba688441c69 Mon Sep 17 00:00:00 2001 From: Roman Kalyakin Date: Thu, 24 Oct 2024 14:08:13 +0200 Subject: [PATCH 2/3] version bump --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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" From 0acee5a430523e211de4de922ae4c76e1d4c130f Mon Sep 17 00:00:00 2001 From: Roman Kalyakin Date: Thu, 24 Oct 2024 14:31:14 +0200 Subject: [PATCH 3/3] unused import --- impresso/util/error.py | 1 - 1 file changed, 1 deletion(-) diff --git a/impresso/util/error.py b/impresso/util/error.py index ca23243..0c7ab47 100644 --- a/impresso/util/error.py +++ b/impresso/util/error.py @@ -1,4 +1,3 @@ -from json import JSONDecodeError from typing import TypeVar from impresso.api_client.models.error import Error as ApiError