Fix fitbit oauth reauth debug logging (#105450)

This commit is contained in:
Allen Porter 2023-12-10 14:09:58 -08:00 committed by Franck Nijhof
parent 399f98a726
commit 0683b8be21
No known key found for this signature in database
GPG key ID: D62583BA8AB11CA3
2 changed files with 7 additions and 1 deletions

View file

@ -60,7 +60,10 @@ class FitbitOAuth2Implementation(AuthImplementation):
resp.raise_for_status()
except aiohttp.ClientResponseError as err:
if _LOGGER.isEnabledFor(logging.DEBUG):
error_body = await resp.text() if not session.closed else ""
try:
error_body = await resp.text()
except aiohttp.ClientError:
error_body = ""
_LOGGER.debug(
"Client response error status=%s, body=%s", err.status, error_body
)

View file

@ -107,18 +107,21 @@ async def test_token_refresh_success(
@pytest.mark.parametrize("token_expiration_time", [12345])
@pytest.mark.parametrize("closing", [True, False])
async def test_token_requires_reauth(
hass: HomeAssistant,
integration_setup: Callable[[], Awaitable[bool]],
config_entry: MockConfigEntry,
aioclient_mock: AiohttpClientMocker,
setup_credentials: None,
closing: bool,
) -> None:
"""Test where token is expired and the refresh attempt requires reauth."""
aioclient_mock.post(
OAUTH2_TOKEN,
status=HTTPStatus.UNAUTHORIZED,
closing=closing,
)
assert not await integration_setup()