Log exception and parser output if it returns invalid JSON

This commit is contained in:
Fabio Manganiello 2019-07-24 23:31:27 +00:00
parent d64c519660
commit beef06fad2

View file

@ -56,7 +56,12 @@ class HttpWebpagePlugin(Plugin):
self.logger.info('Parsing URL {}'.format(url)) self.logger.info('Parsing URL {}'.format(url))
parser = subprocess.Popen(['node', self._mercury_script, url], stdout=subprocess.PIPE) parser = subprocess.Popen(['node', self._mercury_script, url], stdout=subprocess.PIPE)
response = json.loads(parser.stdout.read().decode()) response = parser.stdout.read().decode()
try:
response = json.loads(response)
except Exception as e:
raise RuntimeError('Could not parse JSON: {}. Response: {}'.format(str(e), response))
self.logger.info('Got response from Mercury API: {}'.format(response)) self.logger.info('Got response from Mercury API: {}'.format(response))
title = response.get('title', '{} on {}'.format( title = response.get('title', '{} on {}'.format(