From 6a0c91a8bf9194257a16e698fad7259b11a77702 Mon Sep 17 00:00:00 2001 From: Noemi <45180344+unflxw@users.noreply.github.com> Date: Thu, 7 Mar 2024 16:13:02 +0100 Subject: [PATCH] Handle unexpected validation errors Handle unexpected validation errors, such as AppSignal's servers not being reachable. --- src/appsignal/cli/command.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/appsignal/cli/command.py b/src/appsignal/cli/command.py index 809ee5e..d4d3c45 100644 --- a/src/appsignal/cli/command.py +++ b/src/appsignal/cli/command.py @@ -63,7 +63,16 @@ def _valid_push_api_key(self) -> str | NoReturn: print("Validating API key...") print() - validation_result = PushApiKeyValidator.validate(config) + try: + validation_result = PushApiKeyValidator.validate(config) + except Exception as e: + print( + "Error while validating Push API key: " + f"{e}" + ) + print("Reach us at support@appsignal.com for support.") + raise ExitError(1) from e + if validation_result == "valid": print("✅ API key is valid!") return key @@ -76,7 +85,7 @@ def _valid_push_api_key(self) -> str | NoReturn: else: print( "Error while validating Push API key. HTTP status code: " - "{validation_result}" + f"{validation_result}" ) print("Reach us at support@appsignal.com for support.") raise ExitError(1)