-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
handle known firewall request rejected errors
- Loading branch information
Showing
2 changed files
with
16 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 [email protected] quoting the ID: {support_id}." | ||
) |