remove file on failed download

This commit is contained in:
Matthew Farrellee 2025-08-21 16:39:18 -04:00
parent 5358eaa251
commit d67d679baf
2 changed files with 5 additions and 9 deletions

View file

@ -256,7 +256,8 @@ class S3FilesImpl(Files):
content = response["Body"].read()
except ClientError as e:
if e.response["Error"]["Code"] == "NoSuchKey":
raise ResourceNotFoundError(row["id"], "File content", "files.list()") from e
await self.sql_store.delete("openai_files", where={"id": file_id})
raise ResourceNotFoundError(file_id, "File", "files.list()") from e
raise RuntimeError(f"Failed to download file from S3: {e}") from e
return Response(