Skip to content

Commit 328b938

Browse files
committed
give user an opportunity to handle exceptions
1 parent e31b1a5 commit 328b938

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

binance/websocket/binance_socket_manager.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,12 @@ def read_data(self):
7878
self.logger.error("Websocket connection timeout")
7979
else:
8080
self.logger.error("Websocket exception: {}".format(e))
81-
raise e
81+
self._handle_exception(e)
82+
break
8283
except Exception as e:
8384
self.logger.error("Exception in read_data: {}".format(e))
84-
raise e
85+
self._handle_exception(e)
86+
break
8587

8688
self._handle_data(op_code, frame, data)
8789
self._handle_heartbeat(op_code, frame)
@@ -119,5 +121,10 @@ def _callback(self, callback, *args):
119121
callback(self, *args)
120122
except Exception as e:
121123
self.logger.error("Error from callback {}: {}".format(callback, e))
122-
if self.on_error:
123-
self.on_error(self, e)
124+
self._handle_exception(e)
125+
126+
def _handle_exception(self, e):
127+
if self.on_error:
128+
self.on_error(self, e)
129+
else:
130+
raise e

0 commit comments

Comments
 (0)