fix(chat.py): accept websocket connection before closing it with an error code and reason
This commit is contained in:
parent
66b4bce525
commit
d46aeb2efa
1 changed files with 2 additions and 1 deletions
|
|
@ -19,8 +19,9 @@ async def chat(client_id: str, websocket: WebSocket):
|
||||||
if client_id in chat_manager.in_memory_cache:
|
if client_id in chat_manager.in_memory_cache:
|
||||||
await chat_manager.handle_websocket(client_id, websocket)
|
await chat_manager.handle_websocket(client_id, websocket)
|
||||||
else:
|
else:
|
||||||
|
await websocket.accept()
|
||||||
message = "Please, build the flow before sending messages"
|
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:
|
except WebSocketException as exc:
|
||||||
logger.error(exc)
|
logger.error(exc)
|
||||||
await websocket.close(code=status.WS_1011_INTERNAL_ERROR, reason=str(exc))
|
await websocket.close(code=status.WS_1011_INTERNAL_ERROR, reason=str(exc))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue