Fix iaqualink exception handling after switch to httpx (#87898)

Fix exception handling after switch to httpx
This commit is contained in:
Florent Thoumie 2023-02-12 00:04:59 -08:00 committed by GitHub
parent 32a6280139
commit 6680e819e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 7 deletions

View File

@ -7,7 +7,7 @@ from functools import wraps
import logging
from typing import Any, Concatenate, ParamSpec, TypeVar
import aiohttp.client_exceptions
import httpx
from iaqualink.client import AqualinkClient
from iaqualink.device import (
AqualinkBinarySensor,
@ -77,10 +77,7 @@ async def async_setup_entry( # noqa: C901
_LOGGER.error("Failed to login: %s", login_exception)
await aqualink.close()
return False
except (
asyncio.TimeoutError,
aiohttp.client_exceptions.ClientConnectorError,
) as aio_exception:
except (asyncio.TimeoutError, httpx.HTTPError) as aio_exception:
await aqualink.close()
raise ConfigEntryNotReady(
f"Error while attempting login: {aio_exception}"
@ -149,7 +146,7 @@ async def async_setup_entry( # noqa: C901
try:
await system.update()
except AqualinkServiceException as svc_exception:
except (AqualinkServiceException, httpx.HTTPError) as svc_exception:
if prev is not None:
_LOGGER.warning(
"Failed to refresh system %s state: %s",

View File

@ -3,6 +3,7 @@ from __future__ import annotations
from typing import Any
import httpx
from iaqualink.client import AqualinkClient
from iaqualink.exception import (
AqualinkServiceException,
@ -42,7 +43,7 @@ class AqualinkFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
pass
except AqualinkServiceUnauthorizedException:
errors["base"] = "invalid_auth"
except AqualinkServiceException:
except (AqualinkServiceException, httpx.HTTPError):
errors["base"] = "cannot_connect"
else:
return self.async_create_entry(title=username, data=user_input)