From 7a3f013a8767e30e47bc4db453bed56f5f025314 Mon Sep 17 00:00:00 2001 From: "Nathan.fooo" <86001920+appflowy@users.noreply.github.com> Date: Tue, 2 Jul 2024 13:26:53 +0800 Subject: [PATCH] chore: show ai service error (#5675) --- frontend/rust-lib/flowy-chat/src/chat.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/frontend/rust-lib/flowy-chat/src/chat.rs b/frontend/rust-lib/flowy-chat/src/chat.rs index 2854d12a925b..6c5e06d7a865 100644 --- a/frontend/rust-lib/flowy-chat/src/chat.rs +++ b/frontend/rust-lib/flowy-chat/src/chat.rs @@ -140,12 +140,14 @@ impl Chat { send_notification(&chat_id, ChatNotification::StreamChatMessageError) .payload(pb) .send(); - break; + return Err(err); }, } } }, Err(err) => { + error!("[Chat] failed to stream answer: {}", err); + let _ = text_sink.send(format!("error:{}", err)).await; let pb = ChatMessageErrorPB { chat_id: chat_id.clone(), error_message: err.to_string(), @@ -153,10 +155,15 @@ impl Chat { send_notification(&chat_id, ChatNotification::StreamChatMessageError) .payload(pb) .send(); + return Err(err); }, } send_notification(&chat_id, ChatNotification::FinishStreaming).send(); + if stream_buffer.lock().await.is_empty() { + return Ok(()); + } + let answer = cloud_service .save_answer( &workspace_id, @@ -166,7 +173,6 @@ impl Chat { ) .await?; Self::save_answer(uid, &chat_id, &user_service, answer)?; - Ok::<(), FlowyError>(()) });