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