From 40942f9955276ca045407b6640b49e0f5ba8d46e Mon Sep 17 00:00:00 2001 From: Kyle Mahan Date: Sat, 20 Aug 2016 09:01:25 -0700 Subject: [PATCH] catch error parsing syndicate-to response --- woodwind/views.py | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/woodwind/views.py b/woodwind/views.py index cc66a33..17484f1 100644 --- a/woodwind/views.py +++ b/woodwind/views.py @@ -366,19 +366,23 @@ def update_micropub_syndicate_to(): if content_type: content_type = content_type.split(';', 1)[0] - if content_type == 'application/json': - blob = resp.json() - syndicate_tos = adapt_expanded(blob.get('syndicate-to-expanded')) - if not syndicate_tos: - syndicate_tos = blob.get('syndicate-to') + try: + if content_type == 'application/json': + blob = resp.json() + syndicate_tos = adapt_expanded(blob.get('syndicate-to-expanded')) + if not syndicate_tos: + syndicate_tos = blob.get('syndicate-to') - else: # try to parse query string - syndicate_tos = pyquerystring.parse(resp.text).get('syndicate-to', []) - if isinstance(syndicate_tos, list): - syndicate_tos = list(syndicate_tos) + else: # try to parse query string + syndicate_tos = pyquerystring.parse(resp.text).get('syndicate-to', []) + if isinstance(syndicate_tos, list): + syndicate_tos = list(syndicate_tos) + + flask_login.current_user.set_setting('syndicate-to', syndicate_tos) + db.session.commit() + except ValueError as e: + flask.flash('Could not parse syndicate-to response: {}'.format(e) - flask_login.current_user.set_setting('syndicate-to', syndicate_tos) - db.session.commit() @views.route('/deauthorize')