Skip to content

Commit

Permalink
make parsing even nicer
Browse files Browse the repository at this point in the history
  • Loading branch information
SamuelGabriel committed Jul 15, 2024
1 parent 985c024 commit a6df17d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 16 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "tabpfn-client"
version = "0.0.18"
version = "0.0.19"
requires-python = ">=3.10"
dependencies = [
"httpx>=0.24.1",
Expand Down
45 changes: 30 additions & 15 deletions tabpfn_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,9 @@ def predict(
return result

@staticmethod
def _validate_response(response, method_name, only_version_check=False):
def _validate_response(
response: httpx.Response, method_name, only_version_check=False
):
# If status code is 200, no errors occurred on the server side.
if response.status_code == 200:
return
Expand All @@ -186,22 +188,35 @@ def _validate_response(response, method_name, only_version_check=False):
logger.error(
f"Fail to call {method_name}, response status: {response.status_code}"
)
if (
len(
reponse_split_up := response.text.split(
"The following exception has occurred:"
try:
if (
len(
reponse_split_up := response.text.split(
"The following exception has occurred:"
)
)
> 1
):
relevant_reponse_text = reponse_split_up[1].split(
"debug_error_string"
)[0]
if "ValueError" in relevant_reponse_text:
# Extract the ValueError message
value_error_msg = relevant_reponse_text.split(
"ValueError. Arguments: ("
)[1].split(",)")[0]
# Remove extra quotes and spaces
value_error_msg = value_error_msg.strip("'")
# Raise the ValueError with the extracted message
raise ValueError(value_error_msg)
raise RuntimeError(relevant_reponse_text)
except Exception as e:
if isinstance(e, (ValueError, RuntimeError)):
raise e
raise RuntimeError(
f"Fail to call {method_name} with error: {response.status_code}, reason: "
f"{response.reason_phrase} and text: {response.text}"
)
> 1
):
relevant_reponse_test = reponse_split_up[1].split("debug_error_string")[
0
]
raise RuntimeError(relevant_reponse_test)
raise RuntimeError(
f"Fail to call {method_name} with error: {response.status_code} and reason: "
f"{response.reason_phrase}"
)

def try_connection(self) -> bool:
"""
Expand Down

0 comments on commit a6df17d

Please sign in to comment.