fix: mastodon.py now throws on revoked tokens

This commit is contained in:
codl 2017-09-17 11:05:29 +02:00
parent a787f26e9a
commit cce01b3b51
No known key found for this signature in database
GPG Key ID: 6CD7C8891ED1233A
1 changed files with 8 additions and 7 deletions

View File

@ -78,23 +78,24 @@ def get_api_for_acc(account):
access_token=token.token,
ratelimit_method='throw',
)
try:
# api.verify_credentials()
# doesnt error even if the token is revoked lol
# https://github.com/tootsuite/mastodon/issues/4637
# so we have to do this:
tl = api.timeline()
if 'error' in tl:
return api
except MastodonAPIError as e:
if 'token' in str(e):
if sentry:
sentry.captureMessage('Mastodon auth revoked or incorrect',
extra=locals())
sentry.captureMessage(
'Mastodon auth revoked or incorrect',
extra=locals())
db.session.delete(token)
db.session.commit()
continue
return api
except (MastodonAPIError,
MastodonNetworkError,
raise TemporaryError(e)
except (MastodonNetworkError,
MastodonRatelimitError) as e:
raise TemporaryError(e)