diff options
author | Aaron LI <aaronly.me@outlook.com> | 2016-11-04 14:23:17 +0800 |
---|---|---|
committer | Aaron LI <aaronly.me@outlook.com> | 2016-11-04 14:23:17 +0800 |
commit | f5485223058dd29beacd228f582b0ea40ac42541 (patch) | |
tree | 6b9da77677740116e524e03d5a9d0925401dd4e1 /fg21sim/webui | |
parent | 32efcaff8b0de30b7f3abb56dd195695530bcbfe (diff) | |
download | fg21sim-f5485223058dd29beacd228f582b0ea40ac42541.tar.bz2 |
webui: websocket.py: Fix wrong exception handling
Diffstat (limited to 'fg21sim/webui')
-rw-r--r-- | fg21sim/webui/websocket.py | 36 |
1 files changed, 17 insertions, 19 deletions
diff --git a/fg21sim/webui/websocket.py b/fg21sim/webui/websocket.py index d1501b5..23d097f 100644 --- a/fg21sim/webui/websocket.py +++ b/fg21sim/webui/websocket.py @@ -128,29 +128,27 @@ class FG21simWSHandler(tornado.websocket.WebSocketHandler): except json.JSONDecodeError: logger.warning("WebSocket: {0}: ".format(self.name) + "message is not a valid JSON string") + response = {"status": False, "type": None} except (KeyError, TypeError): logger.warning("WebSocket: %s: skip invalid message" % self.name) - finally: response = {"status": False, "type": None} - msg_response = json.dumps(response) - self.write_message(msg_response) - return - - # Check the message type and dispatch task - if msg_type == "configs": - # Request or set the configurations - response = self._handle_configs(msg) - elif msg_type == "console": - # Control the simulation tasks, or request logging messages - response = self._handle_console(msg) - elif msg_type == "results": - # Request the simulation results - response = self._handle_results(msg) else: - # Message of unknown type - logger.warning("WebSocket: {0}: ".format(self.name) + - "message of unknown type: {0}".format(msg_type)) - response = {"status": False, "type": msg_type} + # Check the message type and dispatch task + if msg_type == "configs": + # Request or set the configurations + response = self._handle_configs(msg) + elif msg_type == "console": + # Control the simulation tasks, or request logging messages + response = self._handle_console(msg) + elif msg_type == "results": + # Request the simulation results + response = self._handle_results(msg) + else: + # Message of unknown type + logger.warning("WebSocket: {0}: ".format(self.name) + + "unknown message type: {0}".format(msg_type)) + response = {"status": False, "type": msg_type} + # msg_response = json.dumps(response) self.write_message(msg_response) |