Google Photos refactor OAuth exceptions (#175271)

This commit is contained in:
Erwin Douna
2026-07-01 16:58:47 +02:00
committed by GitHub
parent 39c10d6d3e
commit c7ba474918
@@ -1,10 +1,15 @@
"""The Google Photos integration."""
from aiohttp import ClientError, ClientResponseError
from aiohttp import ClientError
from google_photos_library_api.api import GooglePhotosLibraryApi
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
from homeassistant.exceptions import (
ConfigEntryAuthFailed,
ConfigEntryNotReady,
OAuth2TokenRequestError,
OAuth2TokenRequestReauthError,
)
from homeassistant.helpers import config_entry_oauth2_flow, config_validation as cv
from homeassistant.helpers.aiohttp_client import async_get_clientsession
from homeassistant.helpers.typing import ConfigType
@@ -48,13 +53,11 @@ async def async_setup_entry(
auth = api.AsyncConfigEntryAuth(web_session, oauth_session)
try:
await auth.async_get_access_token()
except ClientResponseError as err:
if 400 <= err.status < 500:
raise ConfigEntryAuthFailed(
"OAuth session is not valid, reauth required"
) from err
raise ConfigEntryNotReady from err
except ClientError as err:
except OAuth2TokenRequestReauthError as err:
raise ConfigEntryAuthFailed(
"OAuth session is not valid, reauth required"
) from err
except (OAuth2TokenRequestError, ClientError) as err:
raise ConfigEntryNotReady from err
coordinator = GooglePhotosUpdateCoordinator(
hass, entry, GooglePhotosLibraryApi(auth)