Skip to content

Commit 04e4a3b

Browse files
committed
Include some better error handling
1 parent 50619d8 commit 04e4a3b

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

chatlas/_provider_openai.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,16 @@ def stream_text(self, chunk):
275275
def stream_merge_chunks(self, completion, chunk):
276276
if chunk.type == "response.completed":
277277
return chunk.response
278+
elif chunk.type == "response.failed":
279+
error = chunk.response.error
280+
if error is None:
281+
msg = "Request failed with an unknown error."
282+
else:
283+
msg = f"Request failed ({error.code}): {error.message}"
284+
raise RuntimeError(msg)
285+
elif chunk.type == "error":
286+
raise RuntimeError(f"Request errored: {chunk.message}")
287+
278288
# Since this value won't actually be used, we can lie about the type
279289
return cast(Response, None)
280290

0 commit comments

Comments
 (0)