Skip to content

Commit

Permalink
Show proper error message instead of stacktrace if boefje API is unre…
Browse files Browse the repository at this point in the history
…achable
  • Loading branch information
dekkers committed Sep 18, 2024
1 parent dd9eb40 commit 393c36d
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions boefjes/images/oci_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand All @@ -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__":
Expand Down

0 comments on commit 393c36d

Please sign in to comment.