From 57712b3693be78b085525f9c1b78d22fa4d037f6 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Fri, 19 Jul 2019 15:00:06 +0000 Subject: [PATCH] Be more robust in case of Mercury API failures while parsing RSS feeds. TODO: the Mercury API has now been retired and replaced by a library, that however is only available for Node.js. Figure out how to wrap the new library in Python 3 --- platypush/backend/http/request/rss/__init__.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/platypush/backend/http/request/rss/__init__.py b/platypush/backend/http/request/rss/__init__.py index 9c323f38..39062283 100644 --- a/platypush/backend/http/request/rss/__init__.py +++ b/platypush/backend/http/request/rss/__init__.py @@ -87,10 +87,21 @@ class RssUpdates(HttpRequest): raise err if not response.text: - raise RuntimeError("No response from Mercury API for URL {} after {} tries" - .format(link, n_tries)) + self.logger.warning('No response from Mercury API for URL {} after {} tries'.format(link, n_tries)) + return - return response.json()['content'] if response and response.ok else None + if not response.ok: + self.logger.warning('Mercury API call failed with status {}'.format(response.status_code)) + return + + response = response.json() + error = response.get('error') + + if error: + self.logger.warning('Mercury API error: {}'.format(error)) + return + + return response.get('content') def get_new_items(self, response): @@ -161,6 +172,7 @@ class RssUpdates(HttpRequest): except Exception as e: self.logger.warning('Exception encountered while parsing RSS ' + 'RSS feed {}: {}'.format(self.url, str(e))) + self.logger.exception(e) source_record.last_updated_at = parse_start_time digest_filename = None