Skip to content

Commit

Permalink
Log server responses when something fails
Browse files Browse the repository at this point in the history
  • Loading branch information
led02 committed Dec 20, 2023
1 parent 0ac1c29 commit 60ecf7c
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/hermes/commands/deposit/invenio.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ def create_initial_version(self) -> None:

response = self.client.new_deposit()
if not response.ok:
_log.error("Server answered with error code %d:\n%s", response.status_code, response.text)
raise RuntimeError(f"Could not create initial deposit {response.url!r}")

deposit = response.json()
Expand All @@ -288,6 +289,7 @@ def create_new_version(self) -> None:
# Get current deposit
response = self.client.get_deposit(latest_record_id)
if not response.ok:
_log.error("Server answered with error code %d:\n%s", response.status_code, response.text)
raise RuntimeError(f"Failed to get current deposit {response.url!r}")

self.links.update(response.json()["links"])
Expand All @@ -296,6 +298,7 @@ def create_new_version(self) -> None:
deposit_url = self.links["newversion"]
response = self.client.post(deposit_url)
if not response.ok:
_log.error("Server answered with error code %d:\n%s", response.status_code, response.text)
raise RuntimeError(f"Could not create new version deposit {deposit_url!r}")

# Store link to latest draft to be used in :func:`update_metadata`.
Expand All @@ -315,6 +318,7 @@ def update_metadata(self) -> None:
)

if not response.ok:
_log.error("Server answered with error code %d:\n%s", response.status_code, response.text)
raise RuntimeError(f"Could not update metadata of draft {draft_url!r}")

deposit = response.json()
Expand Down Expand Up @@ -356,6 +360,7 @@ def upload_artifacts(self) -> None:
f"{bucket_url}/{path.name}", data=file_content,
)
if not response.ok:
_log.error("Server answered with error code %d:\n%s", response.status_code, response.text)
raise RuntimeError(f"Could not upload file {path.name!r} into bucket {bucket_url!r}")

# This can potentially be used to verify the checksum
Expand All @@ -367,7 +372,7 @@ def publish(self) -> None:
publish_url = self.links["publish"]
response = self.client.post(publish_url)
if not response.ok:
_log.debug(response.text)
_log.error("Server answered with error code %d:\n%s", response.status_code, response.text)
raise RuntimeError(f"Could not publish deposit via {publish_url!r}")

record = response.json()
Expand Down

0 comments on commit 60ecf7c

Please sign in to comment.