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:
parent
a968fd3f92
commit
9d9b044080
19
av98.py
19
av98.py
|
@ -228,28 +228,23 @@ class GeminiClient(cmd.Cmd):
|
||||||
self._debug("Response header: %s." % header)
|
self._debug("Response header: %s." % header)
|
||||||
|
|
||||||
# Catch network errors which may happen on initial connection
|
# Catch network errors which may happen on initial connection
|
||||||
except (socket.gaierror, ConnectionRefusedError,
|
except Exception as err:
|
||||||
ConnectionResetError, TimeoutError, socket.timeout,
|
|
||||||
) as network_error:
|
|
||||||
# Print an error message
|
# Print an error message
|
||||||
if isinstance(network_error, socket.gaierror):
|
if isinstance(err, socket.gaierror):
|
||||||
self.log["dns_failures"] += 1
|
self.log["dns_failures"] += 1
|
||||||
print("ERROR: DNS error!")
|
print("ERROR: DNS error!")
|
||||||
elif isinstance(network_error, ConnectionRefusedError):
|
elif isinstance(err, ConnectionRefusedError):
|
||||||
self.log["refused_connections"] += 1
|
self.log["refused_connections"] += 1
|
||||||
print("ERROR: Connection refused!")
|
print("ERROR: Connection refused!")
|
||||||
elif isinstance(network_error, ConnectionResetError):
|
elif isinstance(err, ConnectionResetError):
|
||||||
self.log["reset_connections"] += 1
|
self.log["reset_connections"] += 1
|
||||||
print("ERROR: Connection reset!")
|
print("ERROR: Connection reset!")
|
||||||
elif isinstance(network_error, (TimeoutError, socket.timeout)):
|
elif isinstance(err, (TimeoutError, socket.timeout)):
|
||||||
self.log["timeouts"] += 1
|
self.log["timeouts"] += 1
|
||||||
print("""ERROR: Connection timed out!
|
print("""ERROR: Connection timed out!
|
||||||
Slow internet connection? Use 'set timeout' to be more patient.""")
|
Slow internet connection? Use 'set timeout' to be more patient.""")
|
||||||
return
|
else:
|
||||||
|
print("ERROR: " + str(err))
|
||||||
# Catch other errors
|
|
||||||
except Exception as err:
|
|
||||||
print("ERROR: " + str(err))
|
|
||||||
return
|
return
|
||||||
|
|
||||||
# Validate header
|
# Validate header
|
||||||
|
|
Loading…
Reference in New Issue