diff --git a/pleroma.py b/pleroma.py index 91ed8e6..8d8bb74 100644 --- a/pleroma.py +++ b/pleroma.py @@ -21,6 +21,9 @@ def http_session_factory(headers={}): class BadRequest(Exception): pass +class LoginFailed(Exception): + pass + class Pleroma: def __init__(self, *, api_base_url, access_token): self.api_base_url = api_base_url.rstrip('/') @@ -59,9 +62,15 @@ class Pleroma: me = verify_credentials async def _get_logged_in_id(self): - if self._logged_in_id is None: - self._logged_in_id = (await self.me())['id'] - return self._logged_in_id + if self._logged_in_id is not None: + return self._logged_in_id + + me = await self.me() + + try: + self._logged_in_id = me['id'] + except KeyError: + raise LoginFailed(me) async def following(self, account_id=None): account_id = account_id or await self._get_logged_in_id()