diff options
author | Trygve Aaberge <trygveaa@gmail.com> | 2019-02-10 21:38:48 +0100 |
---|---|---|
committer | Trygve Aaberge <trygveaa@gmail.com> | 2019-02-15 00:20:26 +0100 |
commit | 4ee9e740af1e550b6b23cb643019570b9e3e66f2 (patch) | |
tree | 659b552fc816284d7a36ddeff538695a036df550 /wee_slack.py | |
parent | 7facf153ac9f39d723882794775fd5392385ae6b (diff) | |
download | wee-slack-4ee9e740af1e550b6b23cb643019570b9e3e66f2.tar.gz |
Move message handling out of exception handling
Remove handling of all exceptions. If an unknown exception happens, it's
better to just let it print a stack trace to the core buffer so we
notice it, instead of just printing it in the debug buffer.
The two specific exceptions we handle are just necessary for the recv
call, so we can move the rest of the lines outside of the exception
handling.
Diffstat (limited to 'wee_slack.py')
-rw-r--r-- | wee_slack.py | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/wee_slack.py b/wee_slack.py index 2026390..0625c29 100644 --- a/wee_slack.py +++ b/wee_slack.py @@ -378,15 +378,7 @@ class EventRouter(object): team = self.teams[team_hash] try: # Read the data from the websocket associated with this team. - data = decode_from_utf8(team.ws.recv()) - message_json = json.loads(data) - metadata = WeeSlackMetadata({ - "team": team_hash, - }).jsonify() - message_json["wee_slack_metadata"] = metadata - if self.recording: - self.record_event(message_json, 'type', 'websocket') - self.receive_json(json.dumps(message_json)) + data = team.ws.recv() except WebSocketConnectionClosedException: w.prnt(team.channel_buffer, 'Lost connection to slack team {} (on receive), reconnecting.'.format(team.domain)) @@ -397,9 +389,15 @@ class EventRouter(object): except ssl.SSLWantReadError: # Expected to happen occasionally on SSL websockets. return w.WEECHAT_RC_OK - except Exception: - dbg('socket issue:\n{}'.format(traceback.format_exc()), level=5) - return w.WEECHAT_RC_OK + + message_json = json.loads(decode_from_utf8(data)) + metadata = WeeSlackMetadata({ + "team": team_hash, + }).jsonify() + message_json["wee_slack_metadata"] = metadata + if self.recording: + self.record_event(message_json, 'type', 'websocket') + self.receive_json(json.dumps(message_json)) def receive_httprequest_callback(self, data, command, return_code, out, err): """ |