From dfd73c05c7777804b14e9e3cec17e38b23c52ebe Mon Sep 17 00:00:00 2001 From: Lucain Date: Wed, 14 Aug 2024 15:21:44 +0200 Subject: [PATCH] Raise with more info on 416 invalid range (#2449) --- src/huggingface_hub/utils/_errors.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/huggingface_hub/utils/_errors.py b/src/huggingface_hub/utils/_errors.py index 6ff09bf7f1..338b622ef4 100644 --- a/src/huggingface_hub/utils/_errors.py +++ b/src/huggingface_hub/utils/_errors.py @@ -366,6 +366,11 @@ def hf_raise_for_status(response: Response, endpoint_name: Optional[str] = None) ) raise HfHubHTTPError(message, response=response) from e + elif response.status_code == 416: + range_header = response.request.headers.get("Range") + message = f"{e}. Requested range: {range_header}. Content-Range: {response.headers.get('Content-Range')}." + raise HfHubHTTPError(message, response=response) from e + # Convert `HTTPError` into a `HfHubHTTPError` to display request information # as well (request id and/or server error message) raise HfHubHTTPError(str(e), response=response) from e