pleroma.py: better _get_logged_in_id error handling

This commit is contained in:
Kay Faraday 2021-12-10 18:51:02 +00:00
parent 766b60c09c
commit 547c1a2407
1 changed files with 12 additions and 3 deletions

View File

@ -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()