Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved upload error reporting #213

Merged
merged 2 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion cumulus_library/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import sys
import sysconfig

import requests
import rich

from cumulus_library import (
Expand Down Expand Up @@ -318,7 +319,11 @@ def run_cli(args: dict):
create_template(args["create_dir"])

elif args["action"] == "upload":
upload.upload_files(args)
try:
upload.upload_files(args)
except requests.RequestException as e:
print(str(e))
exit()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be sys.exit, yeah?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, was just getting to that


# all other actions require connecting to the database
else:
Expand Down
5 changes: 2 additions & 3 deletions cumulus_library/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,8 @@ def upload_data(

if prefetch_res.status_code != 200:
print("Invalid user/site id")
raise requests.RequestException(response=prefetch_res)
prefetch_res.raise_for_status()
res_body = prefetch_res.json()

with open(file_path, "rb") as data_file:
files = {"file": (file_name, data_file)}
upload_req = requests.Request(
Expand All @@ -55,7 +54,7 @@ def upload_data(
upload_res = s.send(upload_req, timeout=60)
if upload_res.status_code != 204:
print(f"Error uploading {study}/{file_name}")
raise requests.RequestException(response=upload_res)
upload_res.raise_for_status()
else:
print("upload_req")
print("headers", upload_req.headers)
Expand Down
Loading