Skip to content

Commit 1f5a047

Browse files
fix: OpenAI error handling fixing for None type error (#111)
OpenAI error handling fixing for None type error
1 parent 17a7b02 commit 1f5a047

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

src/unstract/sdk/adapters/llm/open_ai/src/open_ai.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def parse_llm_err(e: OpenAIAPIError) -> LLMError:
9191
LLMError: Error to be sent to the user
9292
"""
9393
msg = "Error from OpenAI. "
94-
if hasattr(e, "body") and "message" in e.body:
94+
if hasattr(e, "body") and isinstance(e.body, dict) and "message" in e.body:
9595
msg += e.body["message"]
9696
else:
9797
msg += e.message

src/unstract/sdk/llm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ def run_completion(
245245
except OpenAIAPIError as e:
246246
msg = "OpenAI error: "
247247
msg += e.message
248-
if hasattr(e, "body") and "message" in e.body:
248+
if hasattr(e, "body") and isinstance(e.body, dict) and "message" in e.body:
249249
msg += e.body["message"]
250250
if isinstance(e, OpenAIRateLimitError):
251251
raise RateLimitError(msg)

0 commit comments

Comments
 (0)