Skip to content

Commit

Permalink
Fixed #163 and added a handler for socket and OS errors only. I'd rat…
Browse files Browse the repository at this point in the history
…her exception issues be dealt at the app level
  • Loading branch information
Lawouach committed Jul 23, 2015
1 parent b2a76a3 commit 5da9ef5
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions ws4py/websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,22 @@ def received_message(self, message):
"""
pass

def unhandled_error(self, error):
"""
Called whenever a socket, or an OS, error is trapped
by ws4py but not managed by it. The given error is
an instance of `socket.error` or `OSError`.
Note however that application exceptions will not go
through this handler. Instead, do make sure you
protect your code appropriately in `received_message`
or `send`.
The default behaviour of this handler is to log
the error with a message.
"""
logger.exception("Failed to receive data")

def _write(self, b):
"""
Trying to prevent a write operation
Expand Down Expand Up @@ -298,8 +314,8 @@ def once(self):

try:
b = self.sock.recv(self.reading_buffer_size)
except socket.error:
logger.exception("Failed to receive data")
except (socket.error, OSError) as e:
self.unhandled_error(e)
return False
else:
if not self.process(b):
Expand Down

0 comments on commit 5da9ef5

Please sign in to comment.