From 393c36d2d22528c2ac7ad552d606d2817bf060a4 Mon Sep 17 00:00:00 2001 From: Jeroen Dekkers Date: Wed, 18 Sep 2024 11:59:12 +0200 Subject: [PATCH] Show proper error message instead of stacktrace if boefje API is unreachable --- boefjes/images/oci_adapter.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/boefjes/images/oci_adapter.py b/boefjes/images/oci_adapter.py index 32a788a4cf8..0027e11e4be 100755 --- a/boefjes/images/oci_adapter.py +++ b/boefjes/images/oci_adapter.py @@ -9,7 +9,11 @@ def main(): input_url = sys.argv[-1] - boefje_input = httpx.get(input_url).json() + try: + boefje_input = httpx.get(input_url).json() + except httpx.HTTPError as e: + # sys.exit will print the message on stderr and return with exit code 1 + sys.exit(f"Failed to get input from boefje API: {e}") try: os.environ.update(boefje_input["boefje_meta"]["environment"]) @@ -32,7 +36,10 @@ def main(): ], } - httpx.post(boefje_input["output_url"], json=out) + try: + httpx.post(boefje_input["output_url"], json=out) + except httpx.HTTPError as e: + sys.exit(f"Failed to post output to boefje API: {e}") if __name__ == "__main__":