added basic error handling
This commit is contained in:
parent
e453a22361
commit
bb18f128ce
1 changed files with 73 additions and 58 deletions
|
|
@ -50,12 +50,13 @@ export default function ChatModal({
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
function connectWS(){
|
||||||
const newWs = new WebSocket(`ws://127.0.0.1:5003/chat/${flow.id}`);
|
const newWs = new WebSocket(`ws://127.0.0.1:5003/chat/${flow.id}`);
|
||||||
newWs.onopen = () => {
|
newWs.onopen = () => {
|
||||||
console.log("WebSocket connection established!");
|
console.log("WebSocket connection established!");
|
||||||
};
|
};
|
||||||
newWs.onmessage = (event) => {
|
newWs.onmessage = (event) => {
|
||||||
|
try {
|
||||||
const data = JSON.parse(event.data);
|
const data = JSON.parse(event.data);
|
||||||
console.log("Received data:", data);
|
console.log("Received data:", data);
|
||||||
//get chat history
|
//get chat history
|
||||||
|
|
@ -109,17 +110,31 @@ export default function ChatModal({
|
||||||
if (data.type == "file") {
|
if (data.type == "file") {
|
||||||
console.log(data);
|
console.log(data);
|
||||||
}
|
}
|
||||||
// Do something with the data received from the WebSocket
|
} catch (error) {
|
||||||
|
setErrorData({title:event.data})
|
||||||
|
if(newWs.readyState===newWs.CLOSED){
|
||||||
|
window.alert(error)
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
newWs.onclose = (e) => {
|
newWs.onclose = (_) => {
|
||||||
console.log("close");
|
if(open){
|
||||||
setLockChat(false);
|
setLockChat(false);
|
||||||
};
|
setTimeout(() => {
|
||||||
newWs.onerror = (e) => {
|
connectWS()
|
||||||
window.alert("error");
|
}, 100);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
setWs(newWs);
|
setWs(newWs);
|
||||||
|
|
||||||
|
return newWs
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
let newWs = connectWS()
|
||||||
return () => {
|
return () => {
|
||||||
newWs.close();
|
newWs.close();
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue