Skip to content

Commit 98d05d6

Browse files
committed
[NEB-247] Show error event in chat UI (#7022)
<!-- ## title your PR with this format: "[SDK/Dashboard/Portal] Feature/Fix: Concise title for the changes" If you did not copy the branch name from Linear, paste the issue tag here (format is TEAM-0000): ## Notes for the reviewer Anything important to call out? Be sure to also clarify these in your comments. ## How to test Unit tests, playground, etc. --> <!-- start pr-codex --> --- ## 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}` <!-- end pr-codex -->
1 parent f4ac3c2 commit 98d05d6

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

apps/dashboard/src/app/nebula-app/(app)/api/chat.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,24 @@ export async function promptNebula(params: {
152152
break;
153153
}
154154

155+
case "error": {
156+
const data = JSON.parse(event.data) as {
157+
code: number;
158+
error: {
159+
message: string;
160+
};
161+
};
162+
163+
params.handleStream({
164+
event: "error",
165+
data: {
166+
code: data.code,
167+
errorMessage: data.error.message,
168+
},
169+
});
170+
break;
171+
}
172+
155173
case "init": {
156174
const data = JSON.parse(event.data);
157175
params.handleStream({
@@ -242,6 +260,13 @@ type ChatStreamedResponse =
242260
chain_ids: number[];
243261
networks: NebulaContext["networks"];
244262
};
263+
}
264+
| {
265+
event: "error";
266+
data: {
267+
code: number;
268+
errorMessage: string;
269+
};
245270
};
246271

247272
type ChatStreamedEvent =
@@ -269,4 +294,8 @@ type ChatStreamedEvent =
269294
| {
270295
event: "context";
271296
data: string;
297+
}
298+
| {
299+
event: "error";
300+
data: string;
272301
};

apps/dashboard/src/app/nebula-app/(app)/components/ChatPageContent.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,20 @@ export async function handleNebulaPrompt(params: {
578578
});
579579
return;
580580
}
581+
582+
case "error": {
583+
hasReceivedResponse = true;
584+
setMessages((prev) => {
585+
return [
586+
...prev,
587+
{
588+
text: res.data.errorMessage,
589+
type: "error",
590+
},
591+
];
592+
});
593+
return;
594+
}
581595
}
582596
},
583597
context: contextFilters,

0 commit comments

Comments
 (0)