catching socket.timeout using tuple exception #8

This commit is contained in:
tomaae 2020-03-13 02:39:35 +01:00
parent b20d140383
commit 0f7ad23e3c
2 changed files with 15 additions and 2 deletions

View file

@ -22,13 +22,13 @@ class SocketTransport:
"""
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

View file

@ -172,6 +172,19 @@ class MikrotikAPI:
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