From 61063804c250dbcf91594c76a5e8d6e44b1f8641 Mon Sep 17 00:00:00 2001 From: Mark Huth Date: Thu, 10 Nov 2022 10:45:29 +1000 Subject: [PATCH] Handle network exceptions when accessing egg URL (#3588) Signed-off-by: Mark Huth (cherry picked from commit 0a0753d10de4cc0a3ebde90227d151b1beb41640) --- insights/client/__init__.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/insights/client/__init__.py b/insights/client/__init__.py index c6a03b2a75..36914e3666 100644 --- a/insights/client/__init__.py +++ b/insights/client/__init__.py @@ -105,11 +105,14 @@ def get_egg_url(self): url = self.connection.base_url + '/platform' + constants.module_router_path else: url = self.connection.base_url + constants.module_router_path - response = self.connection.get(url) - if response.status_code == 200: - return response.json()["url"] - else: - logger.warning("Unable to fetch egg url. Defaulting to /release") + try: + response = self.connection.get(url) + if response.status_code == 200: + return response.json()["url"] + else: + raise ConnectionError("%s: %s" % (response.status_code, response.reason)) + except ConnectionError as e: + logger.warning("Unable to fetch egg url %s: %s. Defaulting to /release", url, str(e)) return '/release' def fetch(self, force=False):