From 75a96bfa96cb97bd597af2080308e2d6d51f7f5c Mon Sep 17 00:00:00 2001 From: Craig Gumbley Date: Fri, 2 Dec 2022 14:21:26 +0000 Subject: [PATCH] Fix access denied error --- status_cake_exporter/_status_cake.py | 20 ++++++++++++-------- status_cake_exporter/_test_collector.py | 3 +++ 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/status_cake_exporter/_status_cake.py b/status_cake_exporter/_status_cake.py index 1bc871b..3dede72 100644 --- a/status_cake_exporter/_status_cake.py +++ b/status_cake_exporter/_status_cake.py @@ -117,15 +117,19 @@ def list_maintenance_windows(self) -> list[dict[str, Any]]: return response except ForbiddenException as e: - message = json.loads(e.body)["message"] - if "Your current plan has no access to this feature" in message: - logger.warn( - ( - "Your current plan has no access to this feature or your account is " - "using legacy maintenance windows. Skipping maintenance window check." + if e.body: + message = json.loads(e.body)["message"] + if ( + message + and "Your current plan has no access to this feature" in message + ): + logger.warn( + ( + "Your current plan has no access to this feature or your account is " + "using legacy maintenance windows. Skipping maintenance window check." + ) ) - ) - return [] + return [] # re-raise here because it might be genuine. raise e diff --git a/status_cake_exporter/_test_collector.py b/status_cake_exporter/_test_collector.py index d5154f9..b610110 100644 --- a/status_cake_exporter/_test_collector.py +++ b/status_cake_exporter/_test_collector.py @@ -168,8 +168,11 @@ def collect(self): yield uptime_gauge except Exception as e: + import traceback + # This should stop the expoter from crashing if there is an error. logger.fatal(f"A fatal error occurred: {e}") + logger.debug(traceback.format_exc()) finally: logger.info("Collector finished.")