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 { chatMessagePropsType } from "../../../../../types/components";
|
||||||
import { classNames, cn } from "../../../../../utils/utils";
|
import { classNames, cn } from "../../../../../utils/utils";
|
||||||
import FileCard from "../fileComponent";
|
import FileCard from "../fileComponent";
|
||||||
|
import useAlertStore from "../../../../../stores/alertStore";
|
||||||
|
import { Message } from "@radix-ui/react-form";
|
||||||
|
|
||||||
export default function ChatMessage({
|
export default function ChatMessage({
|
||||||
chat,
|
chat,
|
||||||
|
|
@ -33,6 +35,7 @@ export default function ChatMessage({
|
||||||
const [isStreaming, setIsStreaming] = useState(false);
|
const [isStreaming, setIsStreaming] = useState(false);
|
||||||
const eventSource = useRef<EventSource | undefined>(undefined);
|
const eventSource = useRef<EventSource | undefined>(undefined);
|
||||||
const updateFlowPool = useFlowStore((state) => state.updateFlowPool);
|
const updateFlowPool = useFlowStore((state) => state.updateFlowPool);
|
||||||
|
const setErrorData = useAlertStore((state) => state.setErrorData);
|
||||||
const chatMessageRef = useRef(chatMessage);
|
const chatMessageRef = useRef(chatMessage);
|
||||||
|
|
||||||
// Sync ref with state
|
// Sync ref with state
|
||||||
|
|
@ -53,10 +56,14 @@ export default function ChatMessage({
|
||||||
setChatMessage((prev) => prev + parsedData.chunk);
|
setChatMessage((prev) => prev + parsedData.chunk);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
eventSource.current.onerror = (event) => {
|
eventSource.current.onerror = (event:any) => {
|
||||||
setIsStreaming(false);
|
setIsStreaming(false);
|
||||||
eventSource.current?.close();
|
eventSource.current?.close();
|
||||||
setStreamUrl(undefined);
|
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"));
|
reject(new Error("Streaming failed"));
|
||||||
};
|
};
|
||||||
eventSource.current.addEventListener("close", (event) => {
|
eventSource.current.addEventListener("close", (event) => {
|
||||||
|
|
|
||||||
|
|
@ -124,7 +124,7 @@ export default function ChatView({
|
||||||
message: string,
|
message: string,
|
||||||
stream_url?: string
|
stream_url?: string
|
||||||
) {
|
) {
|
||||||
if (message === "") return;
|
// if (message === "") return;
|
||||||
chat.message = message;
|
chat.message = message;
|
||||||
// chat is one of the chatHistory
|
// chat is one of the chatHistory
|
||||||
updateFlowPool(chat.componentId, {
|
updateFlowPool(chat.componentId, {
|
||||||
|
|
|
||||||
|
|
@ -143,7 +143,6 @@ export default function ShareModal({
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
console.log("ShareModal");
|
|
||||||
|
|
||||||
const handleUpdateComponent = () => {
|
const handleUpdateComponent = () => {
|
||||||
handleShareComponent(true);
|
handleShareComponent(true);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue