nicer error message on mastodon app creation failure

also log more exceptions to sentry
This commit is contained in:
codl 2017-08-29 16:41:11 +02:00
parent e07e052d7d
commit d4d30d0530
No known key found for this signature in database
GPG Key ID: 6CD7C8891ED1233A
1 changed files with 27 additions and 13 deletions

View File

@ -88,6 +88,8 @@ def twitter_login_step1():
**app.config.get_namespace("TWITTER_") **app.config.get_namespace("TWITTER_")
)) ))
except (TwitterError, URLError): except (TwitterError, URLError):
if sentry:
sentry.captureException()
return redirect( return redirect(
url_for('index', twitter_login_error='', _anchor='log_in')) url_for('index', twitter_login_error='', _anchor='log_in'))
@ -112,6 +114,8 @@ def twitter_login_step2():
set_session_cookie(session, resp, app.config.get('HTTPS')) set_session_cookie(session, resp, app.config.get('HTTPS'))
return resp return resp
except (TwitterError, URLError): except (TwitterError, URLError):
if sentry:
sentry.captureException()
return redirect( return redirect(
url_for('index', twitter_login_error='', _anchor='log_in')) url_for('index', twitter_login_error='', _anchor='log_in'))
@ -144,6 +148,8 @@ def upload_tweet_archive():
return redirect(url_for('index', _anchor='recent_archives')) return redirect(url_for('index', _anchor='recent_archives'))
except (BadZipFile, TweetArchiveEmptyException): except (BadZipFile, TweetArchiveEmptyException):
if sentry:
sentry.captureException()
return redirect( return redirect(
url_for('index', tweet_archive_failed='', url_for('index', tweet_archive_failed='',
_anchor='tweet_archive_import')) _anchor='tweet_archive_import'))
@ -160,6 +166,8 @@ def settings():
setattr(viewer, attr, request.form[attr]) setattr(viewer, attr, request.form[attr])
db.session.commit() db.session.commit()
except ValueError: except ValueError:
if sentry:
sentry.captureException()
return 400 return 400
return redirect(url_for('index', settings_saved='')) return redirect(url_for('index', settings_saved=''))
@ -267,17 +275,17 @@ def api_viewer_timers():
@app.route('/login/mastodon', methods=('GET', 'POST')) @app.route('/login/mastodon', methods=('GET', 'POST'))
def mastodon_login_step1(instance=None): def mastodon_login_step1(instance=None):
instance_url = (request.args.get('instance_url', None)
or request.form.get('instance_url', None))
if not instance_url:
instances = ( instances = (
MastodonInstance MastodonInstance
.query.filter(MastodonInstance.popularity > 1) .query.filter(MastodonInstance.popularity > 1)
.order_by(db.desc(MastodonInstance.popularity), .order_by(db.desc(MastodonInstance.popularity),
MastodonInstance.instance) MastodonInstance.instance)
.limit(30)) .limit(30))
instance_url = (request.args.get('instance_url', None)
or request.form.get('instance_url', None))
if not instance_url:
return render_template( return render_template(
'mastodon_login.html', instances=instances, 'mastodon_login.html', instances=instances,
address_error=request.method == 'POST', address_error=request.method == 'POST',
@ -289,6 +297,7 @@ def mastodon_login_step1(instance=None):
callback = url_for('mastodon_login_step2', callback = url_for('mastodon_login_step2',
instance=instance_url, _external=True) instance=instance_url, _external=True)
try:
app = lib.mastodon.get_or_create_app( app = lib.mastodon.get_or_create_app(
instance_url, instance_url,
callback, callback,
@ -299,6 +308,11 @@ def mastodon_login_step1(instance=None):
return redirect(lib.mastodon.login_url(app, callback)) return redirect(lib.mastodon.login_url(app, callback))
except Exception:
if sentry:
sentry.captureException()
return redirect(url_for('mastodon_login_step1', error=True))
@app.route('/login/mastodon/callback/<instance>') @app.route('/login/mastodon/callback/<instance>')
def mastodon_login_step2(instance_url): def mastodon_login_step2(instance_url):