Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 4 additions & 5 deletions src/incatools/odk/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,6 @@ def download_file(
elif response.status_code == 304:
logging.info(f"{output.name}: Not modified at {url}")
return 304
elif response.status_code == 404:
logging.warning(f"{output.name}: Not found at {url}")
return 404
Comment thread
gouttegd marked this conversation as resolved.
elif response.status_code in RETRIABLE_HTTP_ERRORS and n_try < max_retry:
n_try += 1
logging.warning(
Expand All @@ -184,8 +181,10 @@ def download_file(
raise DownloadError(f"Timeout when connecting to {hostname}")
except requests.exceptions.ConnectionError:
raise DownloadError(f"Cannot connect to {hostname}")
except requests.exceptions.HTTPError:
raise DownloadError(f"HTTP error when downloading {url}")
except requests.exceptions.HTTPError as e:
raise DownloadError(
f"HTTP {e.response.status_code} error when downloading {url}"
)
except requests.exceptions.ReadTimeout:
raise DownloadError(f"Timeout when downloading {url}")

Expand Down
18 changes: 11 additions & 7 deletions src/incatools/odk/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,15 +204,19 @@ def download(url, output, reference, cache_info, max_retry, try_gzip) -> None:
if reference != output and output.exists():
output.unlink()

try:
for u, c in attempts:
status = download_file(u, output, info, max_retry, c)
for i, attempt in enumerate(attempts):
try:
logging.info(f"{output.name}: Trying download from <{attempt[0]}>")
status = download_file(attempt[0], output, info, max_retry, attempt[1])
if status == 200:
info.to_file(cache_info)
return
elif status == 304:
return
Comment thread
gouttegd marked this conversation as resolved.
if status == 404: # Last attempt failed
raise click.ClickException(f"Cannot download {url}: 404 Not Found")
except DownloadError as e:
raise click.ClickException(f"Cannot download {url}: {e}")
except DownloadError as e:
if i == len(attempts) - 1:
raise click.ClickException(f"Cannot download {url}: {e}")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cosmetic: I assume here that the printed DownloadError always contains the response.status_code (status). If that for some unfathomable reason is not the case I would print it as part of the exception.

else:
logging.warning(
f"{output.name}: Download failed from <{attempt[0]}>: {e}"
)
Loading