Handle client-side errors in message sending and update UI accordingly

This commit is contained in:
2026-04-17 13:06:02 +02:00
parent 47eaded702
commit 7d82ef1acf

View File

@@ -2573,6 +2573,23 @@ async function sendMessage() {
}
console.error('Failed to send message:', error)
if (Number(error?.status) >= 400 && Number(error?.status) < 500) {
setAssistantMessageContent(targetSessionId, assistantMsgId, fullReply, { removeIfEmpty: true })
setChatSessions(prevSessions =>
prevSessions.map(session =>
session.session_id === targetSessionId
? {
...session,
messages: (session.messages || []).filter(message => message.id !== userMsg.id),
}
: session
)
)
setInput(composerSnapshot)
setComposerAttachments(attachmentSnapshot)
window.alert(getErrorText(error))
return
}
setAssistantMessageContent(targetSessionId, assistantMsgId, 'Error: ' + getErrorText(error), { removeIfEmpty: true })
return
}