Skip to content

Commit 147340d

Browse files
committed
use normal exception pattern
1 parent 0fe1d2c commit 147340d

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

alephclient/exports.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
from pathlib import Path
22
from typing import List, Dict
33

4+
from requests import RequestException
5+
from requests.exceptions import HTTPError
6+
47
from alephclient.api import AlephAPI, APIResultSet
58
from alephclient.errors import AlephException
69

@@ -42,15 +45,15 @@ def _get_export(api: AlephAPI, export_id: str) -> Dict:
4245
for export in list_exports(api):
4346
if str(export.get("id")) == str(export_id):
4447
return export
45-
raise AlephException(ValueError(f"Export {export_id} not found"))
48+
raise AlephException(f"Export {export_id} not found")
4649

4750

4851
def download_export(api: AlephAPI, export_id: str, destination: str) -> Path:
4952
"""Download an export archive to the given destination path."""
5053
export = _get_export(api, export_id)
5154
download_url = export.get("links", {}).get("download")
5255
if not download_url:
53-
raise AlephException(ValueError(f"No download link for export {export_id}"))
56+
raise AlephException(f"No download link for export {export_id}")
5457

5558
file_name = export.get("file_name", export_id)
5659
dest = Path(destination)
@@ -61,7 +64,7 @@ def download_export(api: AlephAPI, export_id: str, destination: str) -> Path:
6164
try:
6265
response = api.session.get(download_url, stream=True)
6366
response.raise_for_status()
64-
except Exception as exc:
67+
except (RequestException, HTTPError) as exc:
6568
raise AlephException(exc) from exc
6669

6770
with open(dest, "wb") as fh:

0 commit comments

Comments
 (0)