Skip to content

Commit

Permalink
Catch JSON decoding errors in browser.get
Browse files Browse the repository at this point in the history
  • Loading branch information
kalikiana committed Oct 11, 2021
1 parent 915db1b commit 8d0ed2a
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion openqa_review/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,22 @@ 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:
msg = "Request to {} failed: {}".format(url, str(e))
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):
Expand Down

0 comments on commit 8d0ed2a

Please sign in to comment.