Skip to content

Commit 4fd1970

Browse files
committed
error handling
1 parent 24af0ce commit 4fd1970

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/components/SupportAI.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,26 @@ export default function SupportAI() {
5151
}),
5252
signal,
5353
openWhenHidden: true,
54+
async onopen(response) {
55+
if (!response.ok) {
56+
throw new Error(response.status.toString());
57+
}
58+
59+
return;
60+
},
61+
onerror(error) {
62+
if (error instanceof Error) {
63+
setMessages((messages) => [
64+
...messages,
65+
{
66+
role: "assistant",
67+
content:
68+
"I'm unable to provide an answer to that at the moment. Please rephrase your query and I'll try again.",
69+
},
70+
]);
71+
throw error;
72+
}
73+
},
5474
onmessage(ev) {
5575
if (ev.data === "[DONE]") {
5676
controller.abort();

0 commit comments

Comments
 (0)