Skip to content

Commit 5da9ef5

Browse files
committed
Fixed Lawouach#163 and added a handler for socket and OS errors only. I'd rather exception issues be dealt at the app level
1 parent b2a76a3 commit 5da9ef5

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

ws4py/websocket.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,22 @@ def received_message(self, message):
229229
"""
230230
pass
231231

232+
def unhandled_error(self, error):
233+
"""
234+
Called whenever a socket, or an OS, error is trapped
235+
by ws4py but not managed by it. The given error is
236+
an instance of `socket.error` or `OSError`.
237+
238+
Note however that application exceptions will not go
239+
through this handler. Instead, do make sure you
240+
protect your code appropriately in `received_message`
241+
or `send`.
242+
243+
The default behaviour of this handler is to log
244+
the error with a message.
245+
"""
246+
logger.exception("Failed to receive data")
247+
232248
def _write(self, b):
233249
"""
234250
Trying to prevent a write operation
@@ -298,8 +314,8 @@ def once(self):
298314

299315
try:
300316
b = self.sock.recv(self.reading_buffer_size)
301-
except socket.error:
302-
logger.exception("Failed to receive data")
317+
except (socket.error, OSError) as e:
318+
self.unhandled_error(e)
303319
return False
304320
else:
305321
if not self.process(b):

0 commit comments

Comments
 (0)