Simplify Exception handling a bit. Unlike in VF-1, we can't recover from network errors with redundant mirrors, so there's no need to separate network errors from other errors early on.

This commit is contained in:
Solderpunk 2019-08-13 19:58:05 +03:00
parent a968fd3f92
commit 9d9b044080
1 changed files with 7 additions and 12 deletions

19
av98.py
View File

@ -228,28 +228,23 @@ class GeminiClient(cmd.Cmd):
self._debug("Response header: %s." % header)
# Catch network errors which may happen on initial connection
except (socket.gaierror, ConnectionRefusedError,
ConnectionResetError, TimeoutError, socket.timeout,
) as network_error:
except Exception as err:
# Print an error message
if isinstance(network_error, socket.gaierror):
if isinstance(err, socket.gaierror):
self.log["dns_failures"] += 1
print("ERROR: DNS error!")
elif isinstance(network_error, ConnectionRefusedError):
elif isinstance(err, ConnectionRefusedError):
self.log["refused_connections"] += 1
print("ERROR: Connection refused!")
elif isinstance(network_error, ConnectionResetError):
elif isinstance(err, ConnectionResetError):
self.log["reset_connections"] += 1
print("ERROR: Connection reset!")
elif isinstance(network_error, (TimeoutError, socket.timeout)):
elif isinstance(err, (TimeoutError, socket.timeout)):
self.log["timeouts"] += 1
print("""ERROR: Connection timed out!
Slow internet connection? Use 'set timeout' to be more patient.""")
return
# Catch other errors
except Exception as err:
print("ERROR: " + str(err))
else:
print("ERROR: " + str(err))
return
# Validate header