Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions impresso/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand All @@ -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}"
)
Expand Down
11 changes: 11 additions & 0 deletions impresso/util/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -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}."
)
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down