feat(chat-window): add error handling
This commit is contained in:
parent
4bf69dfdda
commit
e3fef3a1be
4 changed files with 31 additions and 1 deletions
|
@ -5,6 +5,7 @@ import { Document } from '@langchain/core/documents';
|
|||
import Navbar from './Navbar';
|
||||
import Chat from './Chat';
|
||||
import EmptyChat from './EmptyChat';
|
||||
import { toast } from 'sonner';
|
||||
|
||||
export type Message = {
|
||||
id: string;
|
||||
|
@ -92,17 +93,24 @@ const useSocket = (url: string) => {
|
|||
wsURL.search = searchParams.toString();
|
||||
|
||||
const ws = new WebSocket(wsURL.toString());
|
||||
|
||||
ws.onopen = () => {
|
||||
console.log('[DEBUG] open');
|
||||
setWs(ws);
|
||||
};
|
||||
|
||||
ws.onmessage = (e) => {
|
||||
const parsedData = JSON.parse(e.data);
|
||||
if (parsedData.type === 'error') {
|
||||
toast.error(parsedData.data);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
connectWs();
|
||||
}
|
||||
|
||||
return () => {
|
||||
1;
|
||||
ws?.close();
|
||||
console.log('[DEBUG] closed');
|
||||
};
|
||||
|
@ -150,6 +158,12 @@ const ChatWindow = () => {
|
|||
const messageHandler = (e: MessageEvent) => {
|
||||
const data = JSON.parse(e.data);
|
||||
|
||||
if (data.type === 'error') {
|
||||
toast.error(data.data);
|
||||
setLoading(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (data.type === 'sources') {
|
||||
sources = data.data;
|
||||
if (!added) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue