Skip to content

Commit

Permalink
handle errors when opening datafile urls
Browse files Browse the repository at this point in the history
  • Loading branch information
apdavison committed Aug 25, 2023
1 parent 87e12ba commit cc93cbc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
8 changes: 7 additions & 1 deletion api/data_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,13 @@ def download_neo_data(url):
"""
# we first open the url to resolve any redirects and have a consistent
# address for caching.
response = urlopen(url)
try:
response = urlopen(url)
except HTTPError as err:
raise HTTPException(
status_code=err.code,
detail=f"Error retrieving {url}: {err.msg}"
)
resolved_url = response.geturl()

file_path = get_cache_path(resolved_url)
Expand Down
8 changes: 5 additions & 3 deletions test/test_gin.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,11 @@
print("Status code counts")
for key in responses:
print(key, len(responses[key]))

for name, r in responses[500].items():
print(name, r.content.split(b"\n\n")[0])
print()
if key >= 300:
print(f"# {key}")
for name, r in responses[key].items():
print(name, r.content.split(b"\n\n")[0])

timestamp = datetime.now().strftime("%Y%m%d-%H%M%S")
with open(f"results_gin_{timestamp}.pkl", "wb") as fp:
Expand Down

0 comments on commit cc93cbc

Please sign in to comment.