Skip to content

Commit

Permalink
add exception handling in helper functions
Browse files Browse the repository at this point in the history
  • Loading branch information
mathleur authored and jameshawkes committed Oct 10, 2023
1 parent 3a3113a commit c95438f
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion tests/helper_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
import requests


class HTTPError(Exception):
def __init__(self, status_code, message):
self.status_code = status_code
self.message = message
super().__init__(f"HTTPError {status_code}: {message}")


def download_test_data(nexus_url, filename):
local_directory = "./tests/data"

Expand All @@ -15,7 +22,8 @@ def download_test_data(nexus_url, filename):
if not os.path.exists(local_file_path):
session = requests.Session()
response = session.get(nexus_url)
# response.raise_for_status()
if response.status_code != 200:
raise HTTPError(response.status_code, "Failed to download data.")
# Save the downloaded data to the local file
with open(local_file_path, "wb") as f:
f.write(response.content)

0 comments on commit c95438f

Please sign in to comment.