Handle connection error in ws handler
This commit is contained in:
@ -5,7 +5,7 @@ from typing import Iterable, Optional
|
||||
|
||||
import websockets
|
||||
from websockets import WebSocketServerProtocol
|
||||
from websockets.exceptions import ConnectionClosedOK
|
||||
from websockets.exceptions import ConnectionClosedOK, ConnectionClosedError
|
||||
|
||||
from hopper.models.player import Player
|
||||
from hopper.models.product import Product
|
||||
@ -44,6 +44,10 @@ class WSServer(Thread):
|
||||
# we're expecting nothing from client, but read if client sends a message
|
||||
await websocket.recv()
|
||||
except ConnectionClosedOK:
|
||||
logging.info(f"Connection closed OK for client: {websocket.id}")
|
||||
connected = False
|
||||
except ConnectionClosedError:
|
||||
logging.info(f"Connection closed error for client: {websocket.id}")
|
||||
connected = False
|
||||
finally:
|
||||
self.connected_clients.remove(websocket)
|
||||
|
||||
Reference in New Issue
Block a user