From 24d05dc23483af0edcbc7cbe6dd34da6aa944b21 Mon Sep 17 00:00:00 2001 From: Eden Kirin Date: Sat, 6 May 2023 09:38:09 +0200 Subject: [PATCH] Handle connection error in ws handler --- hopper/ws_server.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/hopper/ws_server.py b/hopper/ws_server.py index 6be46ed..9b6ca2c 100644 --- a/hopper/ws_server.py +++ b/hopper/ws_server.py @@ -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)