|
20 | 20 | from databento.common.enums import Delivery |
21 | 21 | from databento.common.enums import Packaging |
22 | 22 | from databento.common.enums import SplitDuration |
| 23 | +from databento.common.error import BentoError |
23 | 24 | from databento.common.parsing import datetime_to_string |
24 | 25 | from databento.common.parsing import optional_datetime_to_string |
25 | 26 | from databento.common.parsing import optional_symbols_list_to_list |
@@ -371,8 +372,11 @@ def _download_file( |
371 | 372 |
|
372 | 373 | logger.debug("Starting download of file %s", output_path.name) |
373 | 374 | with open(output_path, mode=mode) as f: |
374 | | - for chunk in response.iter_content(chunk_size=None): |
375 | | - f.write(chunk) |
| 375 | + try: |
| 376 | + for chunk in response.iter_content(chunk_size=None): |
| 377 | + f.write(chunk) |
| 378 | + except Exception as exc: |
| 379 | + raise BentoError(f"Error downloading file: {exc}") |
376 | 380 | logger.debug("Download of %s completed", output_path.name) |
377 | 381 |
|
378 | 382 | async def download_async( |
@@ -512,9 +516,12 @@ async def _download_file_async( |
512 | 516 |
|
513 | 517 | logger.debug("Starting async download of file %s", output_path.name) |
514 | 518 | with open(output_path, mode=mode) as f: |
515 | | - async for chunk in response.content.iter_chunks(): |
516 | | - data: bytes = chunk[0] |
517 | | - f.write(data) |
| 519 | + try: |
| 520 | + async for chunk in response.content.iter_chunks(): |
| 521 | + data: bytes = chunk[0] |
| 522 | + f.write(data) |
| 523 | + except Exception as exc: |
| 524 | + raise BentoError(f"Error downloading file: {exc}") |
518 | 525 | logger.debug("Download of %s completed", output_path.name) |
519 | 526 |
|
520 | 527 | def _get_file_download_headers_and_mode( |
|
0 commit comments