Update fitbit error handling (#101304)
* Update fitbit error handling * Update exceptions to inherit HomeAssistantError and add reason code * Revert config flow exception mapping hack
This commit is contained in:
parent
1d31def982
commit
c7d533d427
8 changed files with 203 additions and 49 deletions
|
@ -1,8 +1,5 @@
|
|||
"""The fitbit component."""
|
||||
|
||||
from http import HTTPStatus
|
||||
|
||||
import aiohttp
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import Platform
|
||||
|
@ -12,6 +9,7 @@ from homeassistant.helpers import config_entry_oauth2_flow
|
|||
|
||||
from . import api
|
||||
from .const import DOMAIN
|
||||
from .exceptions import FitbitApiException, FitbitAuthException
|
||||
|
||||
PLATFORMS: list[Platform] = [Platform.SENSOR]
|
||||
|
||||
|
@ -31,11 +29,9 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||
)
|
||||
try:
|
||||
await fitbit_api.async_get_access_token()
|
||||
except aiohttp.ClientResponseError as err:
|
||||
if err.status == HTTPStatus.UNAUTHORIZED:
|
||||
raise ConfigEntryAuthFailed from err
|
||||
raise ConfigEntryNotReady from err
|
||||
except aiohttp.ClientError as err:
|
||||
except FitbitAuthException as err:
|
||||
raise ConfigEntryAuthFailed from err
|
||||
except FitbitApiException as err:
|
||||
raise ConfigEntryNotReady from err
|
||||
|
||||
hass.data[DOMAIN][entry.entry_id] = fitbit_api
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue