Skip to content

Commit 1dcb00e

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 1dcb00e

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,26 @@ 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+
error: {
160+
message: string;
161+
};
162+
};
163+
};
164+
165+
params.handleStream({
166+
event: "error",
167+
data: {
168+
code: data.code,
169+
errorMessage: data.error.error.message,
170+
},
171+
});
172+
break;
173+
}
174+
155175
case "init": {
156176
const data = JSON.parse(event.data);
157177
params.handleStream({
@@ -242,6 +262,13 @@ type ChatStreamedResponse =
242262
chain_ids: number[];
243263
networks: NebulaContext["networks"];
244264
};
265+
}
266+
| {
267+
event: "error";
268+
data: {
269+
code: number;
270+
errorMessage: string;
271+
};
245272
};
246273

247274
type ChatStreamedEvent =
@@ -269,4 +296,8 @@ type ChatStreamedEvent =
269296
| {
270297
event: "context";
271298
data: string;
299+
}
300+
| {
301+
event: "error";
302+
data: string;
272303
};

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)