Skip to content

Commit

Permalink
Fix : Prompt service error handling improvement (#35)
Browse files Browse the repository at this point in the history
* Handle errors for json response

* Version bump 0.18.1 -> 0.18.2
  • Loading branch information
Deepak-Kesavan authored Apr 10, 2024
1 parent 1dd4525 commit 4fa116b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/unstract/sdk/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "0.18.1"
__version__ = "0.18.2"


def get_sdk_version():
Expand Down
11 changes: 10 additions & 1 deletion src/unstract/sdk/prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,16 @@ def _post_call(
result["status"] = "OK"
result["structure_output"] = response.text
except RequestException as e:
result["error"] = f"Error occurred: {e}"
# Extract error information from the response if available
error_message = str(e)
content_type = response.headers.get("Content-Type", "").lower()
if "application/json" in content_type:
response_json = response.json()
if "error" in response_json:
error_message = response_json["error"]
elif response.text:
error_message = response.text
result["error"] = error_message
self.tool.stream_log(
f"Error while fetching response for prompt: {result['error']}",
level=LogLevel.ERROR,
Expand Down

0 comments on commit 4fa116b

Please sign in to comment.