Skip to content

Commit 0f7a55d

Browse files
authored
Improve error handling when posting new messages (#892)
* send an error or if no text was written * fix loading indicator * fix lastIsError code
1 parent 7a3c71d commit 0f7a55d

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

src/lib/components/chat/ChatMessage.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@
106106
clearTimeout(pendingTimeout);
107107
108108
// Add loading animation to the last message if update takes more than 600ms
109-
if ((loading && isLast) || emptyLoad) {
109+
if (isLast && loading && emptyLoad) {
110110
pendingTimeout = setTimeout(() => {
111111
if (contentEl) {
112112
loadingEl = new IconLoading({

src/lib/components/chat/ChatWindow.svelte

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,10 @@
8686
const convTreeStore = useConvTreeStore();
8787
8888
$: lastMessage = browser && (messages.find((m) => m.id == $convTreeStore.leaf) as Message);
89-
$: lastIsError = lastMessage && lastMessage.from === "user" && !loading;
89+
$: lastIsError =
90+
lastMessage &&
91+
((lastMessage.from === "user" && !loading) ||
92+
lastMessage.updates?.findIndex((u) => u.type === "status" && u.status === "error") !== -1);
9093
9194
$: sources = files.map((file) => file2base64(file));
9295
@@ -242,7 +245,7 @@
242245
on:click={() => {
243246
if (lastMessage && lastMessage.ancestors) {
244247
dispatch("retry", {
245-
id: lastMessage.ancestors[lastMessage.ancestors.length - 1],
248+
id: lastMessage.id,
246249
});
247250
}
248251
}}

src/routes/conversation/[id]/+server.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,15 @@ export async function POST({ request, locals, params, getClientAddress }) {
377377
}
378378
} catch (e) {
379379
update({ type: "status", status: "error", message: (e as Error).message });
380+
} finally {
381+
// check if no output was generated
382+
if (messageToWriteTo.content === previousText) {
383+
update({
384+
type: "status",
385+
status: "error",
386+
message: "No output was generated. Something went wrong.",
387+
});
388+
}
380389
}
381390

382391
await collections.conversations.updateOne(

0 commit comments

Comments
 (0)