From 213c1eae99707fc66306b885de357ca656dc48cd Mon Sep 17 00:00:00 2001 From: Tomas Kopecek Date: Jan 11 2022 11:32:58 +0000 Subject: PR#3204: lib: refactor variables in is_conn_err() Merges #3204 https://pagure.io/koji/pull-request/3204 Fixes #3213 https://pagure.io/koji/issue/3213 --- diff --git a/koji/__init__.py b/koji/__init__.py index 76e4ec1..0278e30 100644 --- a/koji/__init__.py +++ b/koji/__init__.py @@ -2318,7 +2318,8 @@ def is_conn_error(e): # there is no value to an `isinstance` check here; let's just # assume that if the exception has an 'errno' and it's one of # these values, this is a connection error. - if getattr(e, 'errno', None) in (errno.ECONNRESET, errno.ECONNABORTED, errno.EPIPE): + ERRNOS = (errno.ECONNRESET, errno.ECONNABORTED, errno.EPIPE) + if getattr(e, 'errno', None) in ERRNOS: return True str_e = str(e) if 'BadStatusLine' in str_e or \ @@ -2330,9 +2331,9 @@ def is_conn_error(e): return True try: if isinstance(e, requests.exceptions.ConnectionError): - e2 = getattr(e, 'args', [None])[0] + inner_err = getattr(e, 'args', [None])[0] # same check as unwrapped socket error - if getattr(e2, 'errno', None) in (errno.ECONNRESET, errno.ECONNABORTED, errno.EPIPE): + if getattr(inner_err, 'errno', None) in ERRNOS: return True except (TypeError, AttributeError): pass