From 03efd3187d2f342926efbc908a40e9d1a495fa78 Mon Sep 17 00:00:00 2001 From: Adrien Carpentier Date: Wed, 30 Oct 2024 18:43:04 +0100 Subject: [PATCH] fix: fix sentry error 145755 --- udata_hydra/utils/file.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/udata_hydra/utils/file.py b/udata_hydra/utils/file.py index 93f26c89..bcfcb555 100644 --- a/udata_hydra/utils/file.py +++ b/udata_hydra/utils/file.py @@ -52,15 +52,18 @@ async def download_resource( async with aiohttp.ClientSession( headers={"user-agent": config.USER_AGENT}, raise_for_status=True ) as session: - async with session.get(url, allow_redirects=True) as response: - async for chunk in response.content.iter_chunked(chunk_size): - if max_size_allowed is None or i * chunk_size < max_size_allowed: - tmp_file.write(chunk) - else: - tmp_file.close() - log.warning(f"File {url} is too big, skipping") - raise IOError("File too large to download") - i += 1 + try: + async with session.get(url, allow_redirects=True) as response: + async for chunk in response.content.iter_chunked(chunk_size): + if max_size_allowed is None or i * chunk_size < max_size_allowed: + tmp_file.write(chunk) + else: + tmp_file.close() + log.warning(f"File {url} is too big, skipping") + raise IOError("File too large to download") + i += 1 + except aiohttp.ClientResponseError as e: + raise IOError(f"Error downloading CSV: {e}") tmp_file.close() if magic.from_file(tmp_file.name, mime=True) in [ "application/x-gzip",