From f7dffa99f3148ca42f3dec1ff62e77da8df590dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0t=C4=9Bp=C3=A1n=20Tomsa?= Date: Thu, 2 Jan 2025 17:26:38 +0100 Subject: [PATCH] feat: Detect proxy errors HTTPS proxy introduces several possible error cases, similar to the actual remote server connection: * proxy name resolution (DNS) error, * proxy connection error, * proxy authentication error. The proxy authentication error can only be recognized by a string in the underlying OSError: the outer exception is a plain remote server connection error. Although the proxy is used for HTTPS connection, the actual communication for the proxy itself is HTTP. Thus, specifying a HTTPS protocol for the proxy causes a specific WRONG_VERSION_NUMBER SSL error. --- insights/client/connection.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/insights/client/connection.py b/insights/client/connection.py index d6acf2ae5..e878e6231 100644 --- a/insights/client/connection.py +++ b/insights/client/connection.py @@ -572,7 +572,15 @@ def test_connection(self, rc=0): if isinstance(result, REQUEST_FAILED_EXCEPTIONS): root_cause = _exception_root_cause(result) - if isinstance(result, requests.exceptions.SSLError): + if isinstance(result, requests.exceptions.ProxyError): + proxy_url = self.proxies[urlparse(url).scheme] + if isinstance(root_cause, socket.gaierror): + logger.error(" Could not resolve proxy address %s.", proxy_url) + elif "407 Proxy Authentication Required" in str(root_cause): + logger.error(" Invalid proxy credentials %s.", proxy_url) + else: + logger.error(" Invalid proxy settings %s.", proxy_url) + elif isinstance(result, requests.exceptions.SSLError): if "[SSL: WRONG_VERSION_NUMBER]" in str(root_cause): logger.error(" Invalid protocol.") else: