Skip to content

Commit

Permalink
Fix cannot connect (#277)
Browse files Browse the repository at this point in the history
* Throw proper error on ClientConnectionError

* Nicer message
  • Loading branch information
andrew-codechimp authored Oct 3, 2024
1 parent 2f6b098 commit 8e57eb5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/aiomealie/mealie.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from importlib import metadata
from typing import TYPE_CHECKING, Any, Self

from aiohttp import ClientSession
from aiohttp import ClientSession, ClientConnectionError
from aiohttp.hdrs import METH_GET, METH_POST, METH_PUT, METH_DELETE
from mashumaro.codecs.orjson import ORJSONDecoder
from yarl import URL
Expand Down Expand Up @@ -88,6 +88,9 @@ async def _request(
except asyncio.TimeoutError as exception:
msg = "Timeout occurred while connecting to Mealie"
raise MealieConnectionError(msg) from exception
except ClientConnectionError as exception:
msg = "Client connection error while connecting to Mealie"
raise MealieConnectionError(msg) from exception

if response.status == 400:
text = await response.text()
Expand Down
8 changes: 8 additions & 0 deletions tests/test_mealie.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,14 @@ async def response_handler(_: str, **_kwargs: Any) -> CallbackResult:
assert await mealie_client.get_startup_info()


async def test_client_connection_error() -> None:
"""Test client connection error from mealie."""

async with MealieClient(api_host="https://bad-url") as mealie_client:
with pytest.raises(MealieConnectionError):
assert await mealie_client.get_startup_info()


async def test_about(
responses: aioresponses,
mealie_client: MealieClient,
Expand Down

0 comments on commit 8e57eb5

Please sign in to comment.