From d46aeb2efa03418c62e826da4ead6a01ffcde4ea Mon Sep 17 00:00:00 2001 From: anovazzi1 Date: Fri, 30 Jun 2023 16:27:45 -0300 Subject: [PATCH] fix(chat.py): accept websocket connection before closing it with an error code and reason --- src/backend/langflow/api/v1/chat.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/backend/langflow/api/v1/chat.py b/src/backend/langflow/api/v1/chat.py index 25be65dbb..500e1d0bc 100644 --- a/src/backend/langflow/api/v1/chat.py +++ b/src/backend/langflow/api/v1/chat.py @@ -19,8 +19,9 @@ async def chat(client_id: str, websocket: WebSocket): if client_id in chat_manager.in_memory_cache: await chat_manager.handle_websocket(client_id, websocket) else: + await websocket.accept() message = "Please, build the flow before sending messages" - await websocket.close(code=status.WS_1008_POLICY_VIOLATION, reason=message) + await websocket.close(code=status.WS_1011_INTERNAL_ERROR, reason=message) except WebSocketException as exc: logger.error(exc) await websocket.close(code=status.WS_1011_INTERNAL_ERROR, reason=str(exc))