Fix Google Tasks error handling on DNS failure (#182195)

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Joost Lekkerkerker
2026-09-18 10:26:10 +00:00
committed by Franck Nijhof
co-authored by Claude
parent 3b972d48e0
commit 437b142d2c
2 changed files with 18 additions and 7 deletions
+6 -2
View File
@@ -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)
+12 -5
View File
@@ -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",
),
],
)