From 7fa270fc1057a8b2fd06e62be4d4221ecc7e7f15 Mon Sep 17 00:00:00 2001
From: Andrew Jackson <andrew@codechimp.org>
Date: Thu, 3 Oct 2024 11:16:21 +0100
Subject: [PATCH 1/2] Throw proper error on ClientConnectionError

---
 src/aiomealie/mealie.py | 5 ++++-
 tests/test_mealie.py    | 8 ++++++++
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/src/aiomealie/mealie.py b/src/aiomealie/mealie.py
index 93cd925..73e86bc 100644
--- a/src/aiomealie/mealie.py
+++ b/src/aiomealie/mealie.py
@@ -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
@@ -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"
+            raise MealieConnectionError(msg) from exception
 
         if response.status == 400:
             text = await response.text()
diff --git a/tests/test_mealie.py b/tests/test_mealie.py
index 522667a..664e544 100644
--- a/tests/test_mealie.py
+++ b/tests/test_mealie.py
@@ -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,

From 21715a98209f469d5018b1886d24ecb0325e0532 Mon Sep 17 00:00:00 2001
From: Andrew Jackson <andrew@codechimp.org>
Date: Thu, 3 Oct 2024 11:17:43 +0100
Subject: [PATCH 2/2] Nicer message

---
 src/aiomealie/mealie.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/aiomealie/mealie.py b/src/aiomealie/mealie.py
index 73e86bc..23f009c 100644
--- a/src/aiomealie/mealie.py
+++ b/src/aiomealie/mealie.py
@@ -89,7 +89,7 @@ async def _request(
             msg = "Timeout occurred while connecting to Mealie"
             raise MealieConnectionError(msg) from exception
         except ClientConnectionError as exception:
-            msg = "Client connection error"
+            msg = "Client connection error while connecting to Mealie"
             raise MealieConnectionError(msg) from exception
 
         if response.status == 400: