Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cannot connect #277

Merged
merged 2 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah! I also made a fix on a local branch but couldn't figure out yet how its testable

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I struggled with this as well, but I'm learning 😄

with pytest.raises(MealieConnectionError):
assert await mealie_client.get_startup_info()


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