From 483752e4ed8bcda8ca6b5e5bdc0674af3a1dfa8a Mon Sep 17 00:00:00 2001 From: Christian Dywan Date: Mon, 11 Oct 2021 11:53:10 +0200 Subject: [PATCH] Catch JSON decoding errors in browser.get See: https://progress.opensuse.org/issues/100709 --- openqa_review/browser.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/openqa_review/browser.py b/openqa_review/browser.py index b236718..4395fba 100644 --- a/openqa_review/browser.py +++ b/openqa_review/browser.py @@ -156,7 +156,12 @@ def _get(self, url, as_json=False): # pragma: no cover log.warn(msg) raise DownloadError(msg) - content = r.json() if as_json else r.content.decode("utf8") + try: + content = r.json() if as_json else r.content.decode("utf8") + except JSONDecodeError as e: + msg = 'Unable to decode JSON for {}: {} (Content was: "{}")'.format(url, str(e), r.content.decode("utf8")) + log.warn(msg) + raise DownloadError(msg) return content def json_rpc_get(self, url, method, params, cache=True):