Downloader: log errors when downloading
If an error is returned from HuggingFace, raise it to the calling function. Signed-off-by: kingbri <8082010+kingbri1@users.noreply.github.com>
This commit is contained in:
parent
48bb78c614
commit
c580893054
2 changed files with 22 additions and 11 deletions
|
|
@ -1,6 +1,7 @@
|
|||
import argparse
|
||||
import asyncio
|
||||
import json
|
||||
import traceback
|
||||
from loguru import logger
|
||||
|
||||
from common.downloader import hf_repo_download
|
||||
|
|
@ -10,6 +11,7 @@ from endpoints.server import export_openapi
|
|||
|
||||
|
||||
def download_action(args: argparse.Namespace):
|
||||
try:
|
||||
asyncio.run(
|
||||
hf_repo_download(
|
||||
repo_id=args.repo_id,
|
||||
|
|
@ -20,6 +22,9 @@ def download_action(args: argparse.Namespace):
|
|||
exclude=args.exclude,
|
||||
)
|
||||
)
|
||||
except Exception:
|
||||
exception = traceback.format_exc()
|
||||
logger.error(exception)
|
||||
|
||||
|
||||
def config_export_action(args: argparse.Namespace):
|
||||
|
|
|
|||
|
|
@ -37,8 +37,14 @@ async def _download_file(
|
|||
req_headers = {"Authorization": f"Bearer {token}"} if token else {}
|
||||
|
||||
async with session.get(url, headers=req_headers) as response:
|
||||
# TODO: Change to raise errors
|
||||
assert response.status == 200
|
||||
if not response.ok:
|
||||
error_text = await response.text()
|
||||
raise aiohttp.ClientResponseError(
|
||||
response.request_info,
|
||||
response.history,
|
||||
status=response.status,
|
||||
message=f"HTTP {response.status}: {error_text}",
|
||||
)
|
||||
|
||||
file_size = int(response.headers["Content-Length"])
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue