diff options
author | Trygve Aaberge <trygveaa@gmail.com> | 2019-04-22 13:33:44 +0200 |
---|---|---|
committer | Trygve Aaberge <trygveaa@gmail.com> | 2019-04-23 10:55:49 +0200 |
commit | b162c14bb0d6b5dd81c0059adf2cccda1de1c615 (patch) | |
tree | 6698d04281ee961a9aa2dc5f4f454004644f79f2 /wee_slack.py | |
parent | d4d9f2d4ca13a3faeaf012599d8bb7e74c3b8959 (diff) | |
download | wee-slack-b162c14bb0d6b5dd81c0059adf2cccda1de1c615.tar.gz |
Catch socket errors in receive_ws_callback
Diffstat (limited to 'wee_slack.py')
-rw-r--r-- | wee_slack.py | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/wee_slack.py b/wee_slack.py index e89c8a6..1e86472 100644 --- a/wee_slack.py +++ b/wee_slack.py @@ -7,6 +7,7 @@ from functools import wraps from io import StringIO from itertools import islice, count +import errno import textwrap import time import json @@ -18,6 +19,7 @@ import traceback import collections import ssl import random +import socket import string from websocket import create_connection, WebSocketConnectionClosedException @@ -402,15 +404,18 @@ class EventRouter(object): try: # Read the data from the websocket associated with this team. data = team.ws.recv() - except WebSocketConnectionClosedException: - w.prnt(team.channel_buffer, - 'Lost connection to slack team {} (on receive), reconnecting.'.format(team.domain)) - dbg('receive_ws_callback failed with exception:\n{}'.format(format_exc_tb()), level=5) - team.set_disconnected() - return w.WEECHAT_RC_OK except ssl.SSLWantReadError: # Expected to happen occasionally on SSL websockets. return w.WEECHAT_RC_OK + except (WebSocketConnectionClosedException, socket.error) as e: + if isinstance(e, WebSocketConnectionClosedException) or e.errno in (errno.EPIPE, errno.ECONNRESET, errno.ETIMEDOUT): + w.prnt(team.channel_buffer, + 'Lost connection to slack team {} (on receive), reconnecting.'.format(team.domain)) + dbg('receive_ws_callback failed with exception:\n{}'.format(format_exc_tb()), level=5) + team.set_disconnected() + else: + raise + return w.WEECHAT_RC_OK message_json = json.loads(decode_from_utf8(data)) metadata = WeeSlackMetadata({ |