Add error handling on streaming and fix streaming bug on error
This commit is contained in:
parent
21db135938
commit
dbe067ec86
3 changed files with 9 additions and 3 deletions
|
|
@ -13,6 +13,8 @@ import useFlowStore from "../../../../../stores/flowStore";
|
|||
import { chatMessagePropsType } from "../../../../../types/components";
|
||||
import { classNames, cn } from "../../../../../utils/utils";
|
||||
import FileCard from "../fileComponent";
|
||||
import useAlertStore from "../../../../../stores/alertStore";
|
||||
import { Message } from "@radix-ui/react-form";
|
||||
|
||||
export default function ChatMessage({
|
||||
chat,
|
||||
|
|
@ -33,6 +35,7 @@ export default function ChatMessage({
|
|||
const [isStreaming, setIsStreaming] = useState(false);
|
||||
const eventSource = useRef<EventSource | undefined>(undefined);
|
||||
const updateFlowPool = useFlowStore((state) => state.updateFlowPool);
|
||||
const setErrorData = useAlertStore((state) => state.setErrorData);
|
||||
const chatMessageRef = useRef(chatMessage);
|
||||
|
||||
// Sync ref with state
|
||||
|
|
@ -53,10 +56,14 @@ export default function ChatMessage({
|
|||
setChatMessage((prev) => prev + parsedData.chunk);
|
||||
}
|
||||
};
|
||||
eventSource.current.onerror = (event) => {
|
||||
eventSource.current.onerror = (event:any) => {
|
||||
setIsStreaming(false);
|
||||
eventSource.current?.close();
|
||||
setStreamUrl(undefined);
|
||||
if(JSON.parse(event.data)?.error){
|
||||
setErrorData({title: "Error on Streaming", list: [JSON.parse(event.data)?.error]});
|
||||
}
|
||||
updateChat(chat, chatMessageRef.current);
|
||||
reject(new Error("Streaming failed"));
|
||||
};
|
||||
eventSource.current.addEventListener("close", (event) => {
|
||||
|
|
|
|||
|
|
@ -124,7 +124,7 @@ export default function ChatView({
|
|||
message: string,
|
||||
stream_url?: string
|
||||
) {
|
||||
if (message === "") return;
|
||||
// if (message === "") return;
|
||||
chat.message = message;
|
||||
// chat is one of the chatHistory
|
||||
updateFlowPool(chat.componentId, {
|
||||
|
|
|
|||
|
|
@ -143,7 +143,6 @@ export default function ShareModal({
|
|||
});
|
||||
});
|
||||
};
|
||||
console.log("ShareModal");
|
||||
|
||||
const handleUpdateComponent = () => {
|
||||
handleShareComponent(true);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue