Skip to content

Commit fa71f7e

Browse files
b0z02003bidorffOL
andauthored
TimeoutException should be handled (#8)
* TimeoutException should be handled I believe that the lack of support for TimeoutException may be the root cause of a few issues encountered since the migration to httpx (see home-assistant/core#65727 (comment)) * fix: fix timeout tests Co-authored-by: KCNL0245 <[email protected]>
1 parent 7c5812e commit fa71f7e

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

glances_api/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ async def get_data(self, endpoint):
5454
response = await client.get(
5555
str(url), auth=(self.username, self.password)
5656
)
57-
except httpx.ConnectError:
57+
except (httpx.ConnectError, httpx.TimeoutException):
5858
raise exceptions.GlancesApiConnectionError(f"Connection to {url} failed")
5959

6060
if response.status_code == httpx.codes.UNAUTHORIZED:

tests/test_timeout.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import pytest
44
from pytest_httpx import HTTPXMock
55

6-
from glances_api import Glances
6+
from glances_api import Glances, exceptions
77

88

99
@pytest.mark.asyncio
@@ -18,6 +18,6 @@ def raise_timeout(request):
1818

1919
httpx_mock.add_callback(raise_timeout)
2020

21-
with pytest.raises(httpx.ReadTimeout):
21+
with pytest.raises(exceptions.GlancesApiConnectionError):
2222
client = Glances()
2323
await client.get_metrics("mem")

0 commit comments

Comments
 (0)