Skip to content

Commit

Permalink
better error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-cnivera committed Oct 18, 2024
1 parent b4e3ec2 commit 5bd070c
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions app_utils/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,20 @@ def send_message(
{},
30000,
)
if resp.status_code < 400:
if resp["status"] < 400:
json_resp: Dict[str, Any] = json.loads(resp["content"])
return json_resp
else:
# Remove the link to the github repo from the error message
error_msg = re.sub(
r"\s*Please use https://github\.com/Snowflake-Labs/semantic-model-generator.*",
"",
resp["content"],
)
raise ValueError(error_msg)
err_body = json.loads(resp["content"])
if "message" in err_body:
# Certain errors have a message payload with a link to the github repo, which we should remove.
error_msg = re.sub(
r"\s*Please use https://github\.com/Snowflake-Labs/semantic-model-generator.*",
"",
err_body["message"],
)
raise ValueError(error_msg)
raise ValueError(err_body)

else:
host = st.session_state.host_name
Expand All @@ -68,10 +71,12 @@ def send_message(
return json_resp
else:
err_body = json.loads(resp.text)
# Remove the link to the github repo from the error message
error_msg = re.sub(
r"\s*Please use https://github\.com/Snowflake-Labs/semantic-model-generator.*",
"",
err_body["message"],
)
raise ValueError(error_msg)
if "message" in err_body:
# Certain errors have a message payload with a link to the github repo, which we should remove.
error_msg = re.sub(
r"\s*Please use https://github\.com/Snowflake-Labs/semantic-model-generator.*",
"",
err_body["message"],
)
raise ValueError(error_msg)
raise ValueError(err_body)

0 comments on commit 5bd070c

Please sign in to comment.