From 9d9b0440801df5447052457d62c855651bfcc2d3 Mon Sep 17 00:00:00 2001 From: Solderpunk Date: Tue, 13 Aug 2019 19:58:05 +0300 Subject: [PATCH] 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. --- av98.py | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/av98.py b/av98.py index f1c482c..28fc099 100755 --- a/av98.py +++ b/av98.py @@ -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