Refresh token workaround because expires to fast

This commit is contained in:
Andre Basche 2023-04-14 23:15:07 +02:00
parent e82c14ec99
commit 272556586e
2 changed files with 25 additions and 2 deletions

View file

@ -100,14 +100,18 @@ class HonConnectionHandler(HonBaseConnectionHandler):
) -> AsyncIterator:
kwargs["headers"] = await self._check_headers(kwargs.get("headers", {}))
async with method(*args, **kwargs) as response:
if response.status in [401, 403] and loop == 0:
if (
self._auth.token_expires_soon or response.status in [401, 403]
) and loop == 0:
_LOGGER.info("Try refreshing token...")
await self._auth.refresh()
async with self._intercept(
method, *args, loop=loop + 1, **kwargs
) as result:
yield result
elif response.status in [401, 403] and loop == 1:
elif (
self._auth.token_is_expired or response.status in [401, 403]
) and loop == 1:
_LOGGER.warning(
"%s - Error %s - %s",
response.request_info.url,