mirror of
https://github.com/home-assistant/core.git
synced 2026-09-25 08:51:46 -04:00
Fix Google Tasks error handling on DNS failure (#182195)
Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude
parent
3b972d48e0
commit
437b142d2c
@@ -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)
|
||||
|
||||
@@ -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",
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user