Fix fitbit oauth reauth debug logging (#105450)

pull/104925/head
Allen Porter 2023-12-10 14:09:58 -08:00 committed by GitHub
parent a7155b154e
commit 4752d37df7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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()