Skip to content

Commit

Permalink
Merge pull request #15 from crevetor/fix-ayla-auth-exception
Browse files Browse the repository at this point in the history
Fix KeyError when raising AylaAuthError
  • Loading branch information
rewardone committed Feb 6, 2024
2 parents 668a282 + f83ff46 commit 49d6ef4
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/ayla_iot_unofficial/ayla_iot_unofficial.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,16 @@ def _sign_out_data(self) -> Dict:

def _set_credentials(self, status_code: int, login_result: Dict):
"""Update the internal credentials store. This tracks current bearer token and data needed for token refresh."""
if status_code == 404:
raise AylaAuthError(login_result["error"]["message"] + " (Confirm app_id and app_secret are correct)")
elif status_code == 401:
raise AylaAuthError(login_result["error"]["message"])
if status_code in [404, 401]:
if "message" in login_result["error"]:
msg = login_result["error"]["message"]
else:
msg = login_result["error"]

if status_code == 404:
msg += " (Confirm app_id and app_secret are correct)"

raise AylaAuthError(msg)

self._access_token = login_result["access_token"]
self._refresh_token = login_result["refresh_token"]
Expand Down

0 comments on commit 49d6ef4

Please sign in to comment.