Skip to content

Commit

Permalink
catch error in update_db
Browse files Browse the repository at this point in the history
  • Loading branch information
i-oden committed Oct 24, 2023
1 parent 871caf6 commit c3a33a8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
25 changes: 15 additions & 10 deletions dds_cli/data_getter.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,15 +221,20 @@ def update_db(self, file):
params = {"project": self.project}

# Send file info to API
response_json, _ = dds_cli.utils.perform_request(
DDSEndpoint.FILE_UPDATE,
method="put",
params=params,
json=filename,
headers=self.token,
error_message="Failed to update file information",
)

updated_in_db, message = (True, response_json["message"])
try:
response_json, _ = dds_cli.utils.perform_request(
DDSEndpoint.FILE_UPDATE,
method="put",
params=params,
json=filename,
headers=self.token,
error_message="Failed to update file information",
)
except dds_cli.exceptions.ApiRequestError as err:
updated_in_db = False
message = str(err)
else:
updated_in_db = True
message = response_json["message"]

return updated_in_db, message
5 changes: 3 additions & 2 deletions dds_cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import typing
import http
from typing import Dict, List, Union
import logging

import requests
import rich.console
Expand Down Expand Up @@ -201,11 +202,11 @@ def transform_paths(json_input):
)
except requests.exceptions.RequestException as err:
if isinstance(err, requests.exceptions.ConnectionError):
error_message += ": The database seems to be down."
error_message += f": The database seems to be down -- \n{err}"
elif isinstance(err, requests.exceptions.Timeout):
error_message += ": The request timed out."
else:
error_message += f": Unknown request error -- \n {err}"
error_message += f": Unknown request error -- \n{err}"
raise dds_cli.exceptions.ApiRequestError(message=error_message)

# Get and parse project specific errors
Expand Down

0 comments on commit c3a33a8

Please sign in to comment.