From 8a0e736a2bad1e4ac0dfcd63892034558a1862f6 Mon Sep 17 00:00:00 2001 From: George Peristerakis Date: Tue, 8 Dec 2015 16:02:29 -0500 Subject: Raise exception if the json content is invalid If the json loads function raises, the return content is invalid. The function should log the error and raise the exception. Closes #32 Change-Id: I053b0169c8da47f2a4812cc30783f8a4776f9c2b --- pygerrit/rest/__init__.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'pygerrit') diff --git a/pygerrit/rest/__init__.py b/pygerrit/rest/__init__.py index 49cc434..e578e96 100644 --- a/pygerrit/rest/__init__.py +++ b/pygerrit/rest/__init__.py @@ -41,7 +41,7 @@ def _decode_response(response): requests.HTTPError if the response contains an HTTP error status code. """ - content = response.content + content = response.content.strip() logging.debug(content[:512]) response.raise_for_status() if content.startswith(GERRIT_MAGIC_JSON_PREFIX): @@ -49,7 +49,8 @@ def _decode_response(response): try: return json.loads(content) except ValueError: - return content.strip() + logging.error('Invalid json content: %s' % content) + raise class GerritRestAPI(object): -- cgit v1.2.1