From 98d05d6fb63bd9b5e9132b78a4e806f759467d6f Mon Sep 17 00:00:00 2001 From: MananTank Date: Mon, 12 May 2025 20:26:53 +0000 Subject: [PATCH] [NEB-247] Show error event in chat UI (#7022) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ## PR-Codex overview This PR introduces error handling for chat responses in the `ChatPageContent` and `chat.ts` files. It adds functionality to display error messages when an error event is received. ### Detailed summary - Added handling for `"error"` case in `ChatPageContent.tsx` to update messages with error details. - Implemented parsing of error data in `chat.ts` to extract error code and message. - Updated `ChatStreamedEvent` type to include an `"error"` event with relevant data structure. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` --- .../src/app/nebula-app/(app)/api/chat.ts | 29 +++++++++++++++++++ .../(app)/components/ChatPageContent.tsx | 14 +++++++++ 2 files changed, 43 insertions(+) diff --git a/apps/dashboard/src/app/nebula-app/(app)/api/chat.ts b/apps/dashboard/src/app/nebula-app/(app)/api/chat.ts index 56976c74741..e7dba4b98d2 100644 --- a/apps/dashboard/src/app/nebula-app/(app)/api/chat.ts +++ b/apps/dashboard/src/app/nebula-app/(app)/api/chat.ts @@ -152,6 +152,24 @@ export async function promptNebula(params: { break; } + case "error": { + const data = JSON.parse(event.data) as { + code: number; + error: { + message: string; + }; + }; + + params.handleStream({ + event: "error", + data: { + code: data.code, + errorMessage: data.error.message, + }, + }); + break; + } + case "init": { const data = JSON.parse(event.data); params.handleStream({ @@ -242,6 +260,13 @@ type ChatStreamedResponse = chain_ids: number[]; networks: NebulaContext["networks"]; }; + } + | { + event: "error"; + data: { + code: number; + errorMessage: string; + }; }; type ChatStreamedEvent = @@ -269,4 +294,8 @@ type ChatStreamedEvent = | { event: "context"; data: string; + } + | { + event: "error"; + data: string; }; diff --git a/apps/dashboard/src/app/nebula-app/(app)/components/ChatPageContent.tsx b/apps/dashboard/src/app/nebula-app/(app)/components/ChatPageContent.tsx index bdf6a718e89..e0d28857a65 100644 --- a/apps/dashboard/src/app/nebula-app/(app)/components/ChatPageContent.tsx +++ b/apps/dashboard/src/app/nebula-app/(app)/components/ChatPageContent.tsx @@ -578,6 +578,20 @@ export async function handleNebulaPrompt(params: { }); return; } + + case "error": { + hasReceivedResponse = true; + setMessages((prev) => { + return [ + ...prev, + { + text: res.data.errorMessage, + type: "error", + }, + ]; + }); + return; + } } }, context: contextFilters,