catch error parsing syndicate-to response

This commit is contained in:
Kyle Mahan 2016-08-20 09:01:25 -07:00
parent 4a2d4ad50d
commit 40942f9955

View file

@ -366,19 +366,23 @@ def update_micropub_syndicate_to():
if content_type: if content_type:
content_type = content_type.split(';', 1)[0] content_type = content_type.split(';', 1)[0]
if content_type == 'application/json': try:
blob = resp.json() if content_type == 'application/json':
syndicate_tos = adapt_expanded(blob.get('syndicate-to-expanded')) blob = resp.json()
if not syndicate_tos: syndicate_tos = adapt_expanded(blob.get('syndicate-to-expanded'))
syndicate_tos = blob.get('syndicate-to') if not syndicate_tos:
syndicate_tos = blob.get('syndicate-to')
else: # try to parse query string else: # try to parse query string
syndicate_tos = pyquerystring.parse(resp.text).get('syndicate-to', []) syndicate_tos = pyquerystring.parse(resp.text).get('syndicate-to', [])
if isinstance(syndicate_tos, list): if isinstance(syndicate_tos, list):
syndicate_tos = list(syndicate_tos) 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') @views.route('/deauthorize')