Skip to content

Commit f174139

Browse files
authored
Make HfHubHTTPError inherit from OSError (#3387)
1 parent 16f3ad1 commit f174139

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/huggingface_hub/errors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class OfflineModeIsEnabled(ConnectionError):
3737
"""Raised when a request is made but `HF_HUB_OFFLINE=1` is set as environment variable."""
3838

3939

40-
class HfHubHTTPError(HTTPError):
40+
class HfHubHTTPError(HTTPError, OSError):
4141
"""
4242
HTTPError to inherit from for any custom HTTP Error raised in HF Hub.
4343

tests/test_utils_errors.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import unittest
2+
from unittest.mock import Mock
23

34
import pytest
45
from httpx import Request, Response
@@ -308,3 +309,9 @@ def test_repo_api_regex(url: str, should_match: bool) -> None:
308309
assert REPO_API_REGEX.match(url)
309310
else:
310311
assert REPO_API_REGEX.match(url) is None
312+
313+
314+
def test_hf_hub_http_error_inherits_from_os_error() -> None:
315+
"""Test HfHubHTTPError inherits from OSError."""
316+
with pytest.raises(OSError):
317+
raise HfHubHTTPError("this is a message", response=Mock())

0 commit comments

Comments
 (0)