Skip to content

Commit

Permalink
catching socket.timeout using tuple exception #8
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaae committed Mar 13, 2020
1 parent b20d140 commit 0f7ad23
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ def read(self, length):
"""
data = bytearray()
while len(data) != length:
tmp = None
try:
tmp = self.sock.recv((length - len(data)))
except:
raise ConnectionClosed('Socket recv failed.')
finally:
data += tmp

data += tmp
if not data:
raise ConnectionClosed('Connection unexpectedly closed.')
return data
Expand Down
13 changes: 13 additions & 0 deletions custom_components/mikrotik_router/mikrotikapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,19 @@ def path(self, path) -> list:
self.lock.release()
return None

try:
tuple(response)
except librouteros_custom.exceptions.ConnectionClosed as api_error:
_LOGGER.error("Mikrotik %s error while path %s", self._host, api_error)
self.disconnect()
self.lock.release()
return None
except:
_LOGGER.error("Mikrotik %s error while path %s", self._host, "unknown")
self.disconnect()
self.lock.release()
return None

self.lock.release()
return response if response else None

Expand Down

0 comments on commit 0f7ad23

Please sign in to comment.