From 8d0ed2a3a76983b798c10fa97561156018aef96d 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 | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/openqa_review/browser.py b/openqa_review/browser.py index b236718..6a8a4f2 100644 --- a/openqa_review/browser.py +++ b/openqa_review/browser.py @@ -148,7 +148,9 @@ def _get(self, url, as_json=False): # pragma: no cover msg = "Request to {} was not successful: {}".format(url, str(e)) log.warn(msg) raise DownloadError(msg) + return self.decode_content(r, url, as_json) + def _decode_content(self, url, r, as_json=False): # pragma: no cover try: r.raise_for_status() except requests.exceptions.HTTPError as e: @@ -156,7 +158,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 json.decoder.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):