pleroma.py: better _get_logged_in_id error handling
This commit is contained in:
parent
766b60c09c
commit
547c1a2407
15
pleroma.py
15
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()
|
||||
|
|
Loading…
Reference in New Issue