fix web socket bug that display empty error (#578)
This pull request addresses a bug related to WebSocket functionality that was causing an empty error to be displayed. The bug resulted in incorrect error-handling behavior within the WebSocket implementation, leading to confusion and difficulties in identifying and resolving issues. By addressing this bug and improving the WebSocket error handling mechanism, this pull request significantly enhances the overall stability and reliability of the application.
This commit is contained in:
commit
36669cd64f
4 changed files with 32 additions and 20 deletions
|
|
@ -19,8 +19,11 @@ 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:
|
||||
# We accept the connection but close it immediately
|
||||
# if the flow is not built yet
|
||||
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))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue