Handle connection error in ws handler

This commit is contained in:
Eden Kirin
2023-05-06 09:38:09 +02:00
parent 7fd6ffca25
commit 24d05dc234

View File

@ -5,7 +5,7 @@ from typing import Iterable, Optional
import websockets import websockets
from websockets import WebSocketServerProtocol from websockets import WebSocketServerProtocol
from websockets.exceptions import ConnectionClosedOK from websockets.exceptions import ConnectionClosedOK, ConnectionClosedError
from hopper.models.player import Player from hopper.models.player import Player
from hopper.models.product import Product 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 # we're expecting nothing from client, but read if client sends a message
await websocket.recv() await websocket.recv()
except ConnectionClosedOK: 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 connected = False
finally: finally:
self.connected_clients.remove(websocket) self.connected_clients.remove(websocket)