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:
parent
38eb1a2d79
commit
927379b245
2 changed files with 5 additions and 3 deletions
|
|
@ -191,7 +191,7 @@ class ChatManager(Service):
|
||||||
json_payload = await websocket.receive_json()
|
json_payload = await websocket.receive_json()
|
||||||
try:
|
try:
|
||||||
payload = orjson.loads(json_payload)
|
payload = orjson.loads(json_payload)
|
||||||
except TypeError:
|
except Exception:
|
||||||
payload = json_payload
|
payload = json_payload
|
||||||
if "clear_history" in payload:
|
if "clear_history" in payload:
|
||||||
self.chat_history.history[client_id] = []
|
self.chat_history.history[client_id] = []
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ import { CHAT_FORM_DIALOG_SUBTITLE } from "../../constants/constants";
|
||||||
import { TabsContext } from "../../contexts/tabsContext";
|
import { TabsContext } from "../../contexts/tabsContext";
|
||||||
import { TabsState } from "../../types/tabs";
|
import { TabsState } from "../../types/tabs";
|
||||||
import { validateNodes } from "../../utils/reactflowUtils";
|
import { validateNodes } from "../../utils/reactflowUtils";
|
||||||
|
import { AuthContext } from "../../contexts/authContext";
|
||||||
|
|
||||||
export default function FormModal({
|
export default function FormModal({
|
||||||
flow,
|
flow,
|
||||||
|
|
@ -60,6 +61,7 @@ export default function FormModal({
|
||||||
|
|
||||||
const [chatHistory, setChatHistory] = useState<ChatMessageType[]>([]);
|
const [chatHistory, setChatHistory] = useState<ChatMessageType[]>([]);
|
||||||
const { reactFlowInstance } = useContext(typesContext);
|
const { reactFlowInstance } = useContext(typesContext);
|
||||||
|
const {accessToken} = useContext(AuthContext);
|
||||||
const { setErrorData } = useContext(alertContext);
|
const { setErrorData } = useContext(alertContext);
|
||||||
const ws = useRef<WebSocket | null>(null);
|
const ws = useRef<WebSocket | null>(null);
|
||||||
const [lockChat, setLockChat] = useState(false);
|
const [lockChat, setLockChat] = useState(false);
|
||||||
|
|
@ -160,7 +162,7 @@ export default function FormModal({
|
||||||
}, 1000);
|
}, 1000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//TODO improve check of user authentication
|
||||||
function getWebSocketUrl(
|
function getWebSocketUrl(
|
||||||
chatId: string,
|
chatId: string,
|
||||||
isDevelopment: boolean = false
|
isDevelopment: boolean = false
|
||||||
|
|
@ -173,7 +175,7 @@ export default function FormModal({
|
||||||
|
|
||||||
return `${
|
return `${
|
||||||
isDevelopment ? "ws" : webSocketProtocol
|
isDevelopment ? "ws" : webSocketProtocol
|
||||||
}://${host}${chatEndpoint}`;
|
}://${host}${chatEndpoint}?token=${accessToken}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleWsMessage(data: any) {
|
function handleWsMessage(data: any) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue