Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle Sentry issue #145755 #210

Closed
wants to merge 2 commits into from
Closed
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
21 changes: 12 additions & 9 deletions udata_hydra/utils/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
9 changes: 8 additions & 1 deletion udata_hydra/utils/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,11 @@ async def send(dataset_id: str, resource_id: str, document: dict) -> None:
async with aiohttp.ClientSession() as session:
async with session.put(uri, json=document, headers=headers) as resp:
# we're raising since we should be in a worker thread
resp.raise_for_status()
if resp.status == 404:
raise IOError("Resource not found on udata")
elif resp.status == 502:
raise IOError("Resource has been deleted on udata")
if resp.status == 502:
raise IOError("Udata is unreachable")
else:
resp.raise_for_status()