From 9a564a846af3aa1fbeb5cb2e53e36f061017dc57 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Wed, 10 Feb 2021 11:56:08 -0800 Subject: [PATCH 1/2] Better error handling and loggin in get_data --- bookwyrm/connectors/abstract_connector.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/bookwyrm/connectors/abstract_connector.py b/bookwyrm/connectors/abstract_connector.py index ab9900a7e..9bc23698b 100644 --- a/bookwyrm/connectors/abstract_connector.py +++ b/bookwyrm/connectors/abstract_connector.py @@ -210,13 +210,20 @@ def get_data(url): 'User-Agent': settings.USER_AGENT, }, ) - except (RequestError, SSLError): + except (RequestError, SSLError) as e: + logger.exception(e) raise ConnectorException() + if not resp.ok: - resp.raise_for_status() + try: + resp.raise_for_status() + except requests.exceptions.HTTPError as e: + logger.exception(e) + raise ConnectorException() try: data = resp.json() - except ValueError: + except ValueError as e: + logger.exception(e) raise ConnectorException() return data From f46a708f7e19a7120d34ef498de654d0265587a8 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Wed, 10 Feb 2021 12:00:16 -0800 Subject: [PATCH 2/2] Handle connector exceptions with sketchy book data from OL --- bookwyrm/connectors/abstract_connector.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bookwyrm/connectors/abstract_connector.py b/bookwyrm/connectors/abstract_connector.py index 9bc23698b..f822fc5d1 100644 --- a/bookwyrm/connectors/abstract_connector.py +++ b/bookwyrm/connectors/abstract_connector.py @@ -107,7 +107,7 @@ class AbstractConnector(AbstractMinimalConnector): if self.is_work_data(data): try: edition_data = self.get_edition_from_work_data(data) - except KeyError: + except (KeyError, ConnectorException): # hack: re-use the work data as the edition data # this is why remote ids aren't necessarily unique edition_data = data @@ -116,7 +116,7 @@ class AbstractConnector(AbstractMinimalConnector): try: work_data = self.get_work_from_edition_data(data) work_data = dict_from_mappings(work_data, self.book_mappings) - except KeyError: + except (KeyError, ConnectorException): work_data = mapped_data edition_data = data