Ensure JSON isn't read on no HTTP response body
This patch moves the json.loads(body) call in the HTTP response handling to after the check for non- 200-300 return codes. This gets rid of the ValueError exception raise when you hit, for instance, a 400 or 404. Also changes a number of logger.exception() calls to logger.debug() calls, since some exceptions are expected and should not be logged as exceptions per-se. fixes LP bug#1067512 Change-Id: If66fb1846ddc19da5bc2f15c6e0dd09019a56932
This commit is contained in:
@@ -127,6 +127,13 @@ class HTTPClient(httplib2.Http):
|
|||||||
**request_kwargs)
|
**request_kwargs)
|
||||||
self.http_log_resp(resp, body)
|
self.http_log_resp(resp, body)
|
||||||
|
|
||||||
|
if resp.status in (400, 401, 403, 404, 408, 409, 413, 500, 501):
|
||||||
|
_logger.debug("Request returned failure status.")
|
||||||
|
raise exceptions.from_response(resp, body)
|
||||||
|
elif resp.status in (301, 302, 305):
|
||||||
|
# Redirected. Reissue the request to the new location.
|
||||||
|
return self.request(resp['location'], method, **kwargs)
|
||||||
|
|
||||||
if body:
|
if body:
|
||||||
try:
|
try:
|
||||||
body = json.loads(body)
|
body = json.loads(body)
|
||||||
@@ -136,13 +143,6 @@ class HTTPClient(httplib2.Http):
|
|||||||
_logger.debug("No body was returned.")
|
_logger.debug("No body was returned.")
|
||||||
body = None
|
body = None
|
||||||
|
|
||||||
if resp.status in (400, 401, 403, 404, 408, 409, 413, 500, 501):
|
|
||||||
_logger.exception("Request returned failure status.")
|
|
||||||
raise exceptions.from_response(resp, body)
|
|
||||||
elif resp.status in (301, 302, 305):
|
|
||||||
# Redirected. Reissue the request to the new location.
|
|
||||||
return self.request(resp['location'], method, **kwargs)
|
|
||||||
|
|
||||||
return resp, body
|
return resp, body
|
||||||
|
|
||||||
def _cs_request(self, url, method, **kwargs):
|
def _cs_request(self, url, method, **kwargs):
|
||||||
|
@@ -106,9 +106,9 @@ class Client(client.HTTPClient):
|
|||||||
self._extract_service_catalog(self.auth_url, raw_token)
|
self._extract_service_catalog(self.auth_url, raw_token)
|
||||||
return True
|
return True
|
||||||
except (exceptions.AuthorizationFailure, exceptions.Unauthorized):
|
except (exceptions.AuthorizationFailure, exceptions.Unauthorized):
|
||||||
|
_logger.debug("Authorization Failed.")
|
||||||
raise
|
raise
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
_logger.exception("Authorization Failed.")
|
|
||||||
raise exceptions.AuthorizationFailure("Authorization Failed: "
|
raise exceptions.AuthorizationFailure("Authorization Failed: "
|
||||||
"%s" % e)
|
"%s" % e)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user