Skip to content

Commit bf2bb5f

Browse files
authored
Merge pull request #46 from Azure-Samples/howie/error-msg
Now display error messages such as rate limit
2 parents 604e621 + e0774b4 commit bf2bb5f

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/api/routes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ async def on_thread_message(self, message: ThreadMessage) -> Optional[str]:
8585
async def on_thread_run(self, run: ThreadRun) -> Optional[str]:
8686
logger.info("MyEventHandler: on_thread_run event received")
8787
run_information = f"ThreadRun status: {run.status}, thread ID: {run.thread_id}"
88-
if run.status == "failed":
89-
run_information += f", error: {run.last_error}"
9088
stream_data = {'content': run_information, 'type': 'thread_run'}
89+
if run.status == "failed":
90+
stream_data['error'] = run.last_error.as_dict()
9191
return serialize_sse_event(stream_data)
9292

9393
async def on_error(self, data: str) -> Optional[str]:

src/api/static/ChatClient.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,19 @@ class ChatClient {
106106

107107
console.log("[ChatClient] Parsed SSE event:", data);
108108

109+
if (data.error) {
110+
if (!messageDiv) {
111+
messageDiv = this.ui.createAssistantMessageDiv();
112+
console.log("[ChatClient] Created new messageDiv for assistant.");
113+
}
114+
this.ui.appendAssistantMessage(
115+
messageDiv,
116+
data.error.message || "An error occurred.",
117+
false
118+
);
119+
return;
120+
}
121+
109122
// Check the data type to decide how to update the UI
110123
if (data.type === "stream_end") {
111124
// End of the stream

0 commit comments

Comments
 (0)