From 78b44897aa4f963e58921d5c24cd933bb428d31d Mon Sep 17 00:00:00 2001 From: AURUMVORXX Date: Mon, 19 May 2025 19:18:26 +0300 Subject: [PATCH] feat: Removed disconnect on error while parsing a message --- src/pyg2o/server.py | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/pyg2o/server.py b/src/pyg2o/server.py index b0b0ee3..fae57ff 100644 --- a/src/pyg2o/server.py +++ b/src/pyg2o/server.py @@ -138,19 +138,22 @@ class PythonWebsocketServer: try: async for message in websocket: - - message_json = json.loads(message) - if ('type' not in message_json or - 'uuid' not in message_json or - 'data' not in message_json): - return - - await self._callMessage(message_json['type'], message_json) + try: + message_json = json.loads(message) + if ('type' not in message_json or + 'uuid' not in message_json or + 'data' not in message_json): + self.logger.error(f'[PyG2O] Expected message with (type, uuid, data) fields, got: {message_json}') + continue + + await self._callMessage(message_json['type'], message_json) - except json.JSONDecodeError as e: - self.logger.exception(f'[PyG2O] JSON Exception: {e}') - except Exception as e: - self.logger.exception(f'[PyG2O] Exception: {e}') + except json.JSONDecodeError as e: + self.logger.exception(f'[PyG2O] JSON Exception: {e}') + continue + except Exception as e: + self.logger.exception(f'[PyG2O] Exception: {e}') + continue finally: if (not self.silent): self.logger.info('Client disconnected')