fix(manager.py): catch all exceptions instead of just TypeError when loading JSON payload to handle any parsing errors

feat(index.tsx): add authentication token to WebSocket URL to authenticate the user
This commit is contained in:
anovazzi1 2023-08-25 18:15:59 -03:00
commit 927379b245
2 changed files with 5 additions and 3 deletions

View file

@ -191,7 +191,7 @@ class ChatManager(Service):
json_payload = await websocket.receive_json()
try:
payload = orjson.loads(json_payload)
except TypeError:
except Exception:
payload = json_payload
if "clear_history" in payload:
self.chat_history.history[client_id] = []

View file

@ -26,6 +26,7 @@ import { CHAT_FORM_DIALOG_SUBTITLE } from "../../constants/constants";
import { TabsContext } from "../../contexts/tabsContext";
import { TabsState } from "../../types/tabs";
import { validateNodes } from "../../utils/reactflowUtils";
import { AuthContext } from "../../contexts/authContext";
export default function FormModal({
flow,
@ -60,6 +61,7 @@ export default function FormModal({
const [chatHistory, setChatHistory] = useState<ChatMessageType[]>([]);
const { reactFlowInstance } = useContext(typesContext);
const {accessToken} = useContext(AuthContext);
const { setErrorData } = useContext(alertContext);
const ws = useRef<WebSocket | null>(null);
const [lockChat, setLockChat] = useState(false);
@ -160,7 +162,7 @@ export default function FormModal({
}, 1000);
}
}
//TODO improve check of user authentication
function getWebSocketUrl(
chatId: string,
isDevelopment: boolean = false
@ -173,7 +175,7 @@ export default function FormModal({
return `${
isDevelopment ? "ws" : webSocketProtocol
}://${host}${chatEndpoint}`;
}://${host}${chatEndpoint}?token=${accessToken}`;
}
function handleWsMessage(data: any) {