report revoked or otherwise erroneous creds to sentry

This commit is contained in:
codl 2017-09-02 10:43:52 +02:00
parent 2c02dd63bc
commit 9bc92fc1f0
No known key found for this signature in database
GPG Key ID: 6CD7C8891ED1233A
2 changed files with 21 additions and 2 deletions

View File

@ -2,7 +2,7 @@ from mastodon import Mastodon
from mastodon.Mastodon import MastodonAPIError
from model import MastodonApp, Account, OAuthToken, Post
from requests import head
from app import db
from app import db, sentry
from math import inf
import iso8601
@ -83,6 +83,15 @@ def get_api_for_acc(account):
# so we have to do this:
tl = api.timeline()
if 'error' in tl:
if sentry:
sentry.capture(
'lib.mastodon.creds_error',
stack=True,
data=dict(
locals=locals(),
account=account,
)
)
db.session.delete(token)
continue
return api

View File

@ -1,7 +1,7 @@
from twitter import Twitter, OAuth, TwitterHTTPError
from werkzeug.urls import url_decode
from model import OAuthToken, Account, Post, TwitterArchive
from app import db, app
from app import db, app, sentry
from math import inf
from datetime import datetime
import locale
@ -79,6 +79,16 @@ def get_twitter_for_acc(account):
except TwitterHTTPError as e:
if e.e.code == 401:
# token revoked
if sentry:
sentry.capture(
'lib.twitter.creds_error',
stack=True,
data=dict(
locals=locals(),
account=account,
)
)
db.session.delete(token)
db.session.commit()
else: