fix(playout): remove empty file when the download request failed (#2864)

This commit is contained in:
Jonas L 2024-01-01 13:16:13 +01:00 committed by GitHub
parent 72268ad9bb
commit 2facbfaff2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 6 deletions

View File

@ -50,13 +50,15 @@ class PypoFile(Thread):
file_event.local_filepath,
)
try:
with file_event.local_filepath.open("wb") as file_fd:
try:
with file_event.local_filepath.open("wb") as file_fd:
response = self.api_client.download_file(file_event.id, stream=True)
for chunk in response.iter_content(chunk_size=8192):
file_fd.write(chunk)
except requests.exceptions.HTTPError as exception:
file_event.local_filepath.unlink(missing_ok=True)
raise RuntimeError(
f"could not download file {file_event.id}"
) from exception