From 437b142d2ce36b717692a37aab83f783c86f069f Mon Sep 17 00:00:00 2001 From: Joost Lekkerkerker Date: Mon, 14 Sep 2026 16:29:30 +0200 Subject: [PATCH] Fix Google Tasks error handling on DNS failure (#182195) Co-authored-by: Claude --- homeassistant/components/google_tasks/api.py | 8 ++++++-- tests/components/google_tasks/test_init.py | 17 ++++++++++++----- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/homeassistant/components/google_tasks/api.py b/homeassistant/components/google_tasks/api.py index 4b1cca8089d3..f59b48061630 100644 --- a/homeassistant/components/google_tasks/api.py +++ b/homeassistant/components/google_tasks/api.py @@ -152,9 +152,13 @@ class AsyncConfigEntryAuth: async def _execute(self, request: HttpRequest | BatchHttpRequest) -> Any: try: result = await self._hass.async_add_executor_job(request.execute) - except (HttpError, ServerNotFoundError) as err: + except HttpError as err: raise GoogleTasksApiError( - f"Google Tasks API responded with: {err.reason or err.status_code})" + f"Google Tasks API responded with: {err.reason or err.status_code}" + ) from err + except ServerNotFoundError as err: + raise GoogleTasksApiError( + f"Unable to reach the Google Tasks API: {err}" ) from err if result: _raise_if_error(result) diff --git a/tests/components/google_tasks/test_init.py b/tests/components/google_tasks/test_init.py index c1ed1cf609f0..adceebead0d9 100644 --- a/tests/components/google_tasks/test_init.py +++ b/tests/components/google_tasks/test_init.py @@ -8,7 +8,7 @@ import time from unittest.mock import Mock, patch from aiohttp import ClientError -from httplib2 import Response +from httplib2 import Response, ServerNotFoundError import pytest from homeassistant.components.google_tasks import DOMAIN @@ -131,16 +131,23 @@ async def test_expired_token_refresh_failure( @pytest.mark.parametrize( "response_handler", [ - ([(Response({"status": HTTPStatus.INTERNAL_SERVER_ERROR}), b"")]), - # First request succeeds, second request fails - ( + pytest.param( + [(Response({"status": HTTPStatus.INTERNAL_SERVER_ERROR}), b"")], + id="first_request_fails", + ), + pytest.param( [ ( Response({"status": HTTPStatus.OK}), json.dumps(LIST_TASK_LIST_RESPONSE), ), (Response({"status": HTTPStatus.INTERNAL_SERVER_ERROR}), b""), - ] + ], + id="second_request_fails", + ), + pytest.param( + [ServerNotFoundError("Unable to find the server at tasks.googleapis.com")], + id="server_not_found", ), ], )