Skip to content

Commit

Permalink
Improve handling of invalid tokens (#53)
Browse files Browse the repository at this point in the history
* Improve handling of invalid tokens

This integration is currently failing for me due to an invalid grant. Handle this in `async_setup_entry` so that reauth is triggered.

```
DEBUG (MainThread) [homeassistant.helpers.config_entry_oauth2_flow] Token request failed with status=400, body={"reason":"Invalid Token!","error":"invalid_grant"}
```

* Update __init__.py

* Update common.py

Co-authored-by: Raman Gupta <[email protected]>
  • Loading branch information
joshuaspence and raman325 authored Mar 8, 2022
1 parent bc47844 commit ab97699
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion custom_components/zoom/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
try:
my_profile = await api.async_get_my_user_profile()
except (HTTPUnauthorized, ClientResponseError) as err:
if isinstance(err, ClientResponseError) and err.status != 401:
if isinstance(err, ClientResponseError) and err.status not in (400, 401):
return False

# If we are not authorized, we need to revalidate OAuth
Expand Down
8 changes: 4 additions & 4 deletions custom_components/zoom/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ async def _async_update_data(self) -> Dict[str, Any]:
"""Update data via library."""
try:
return await self._api.async_get_my_user_profile()
except:
raise UpdateFailed
except Exception as err:
raise UpdateFailed from err


class ZoomContactListDataUpdateCoordinator(DataUpdateCoordinator):
Expand All @@ -174,5 +174,5 @@ async def _async_update_data(self) -> List[Dict[str, str]]:
"""Update data via library."""
try:
return await self._api.async_get_contacts(self._contact_types)
except:
raise UpdateFailed
except Exception as err:
raise UpdateFailed from err

0 comments on commit ab97699

Please sign in to comment.