Display a better error message on HTTP exception
Instead of just getting the HTTP code, the message from the actual exception is printed to the console Change-Id: I43265e1e01e3e972e444778b3058637c0e1fd441
This commit is contained in:
parent
e1ce4162e4
commit
c7130de0a9
@ -163,9 +163,7 @@ class HTTPClient(object):
|
||||
self.log_http_response(resp)
|
||||
|
||||
if 400 <= resp.status < 600:
|
||||
if resp.status != 404:
|
||||
LOG.warn("Request returned failure status %s" % resp.status)
|
||||
raise exc.from_response(resp)
|
||||
raise exc.from_response(resp, body_iter)
|
||||
elif resp.status in (301, 302, 305):
|
||||
# Redirected. Reissue the request to the new location.
|
||||
location = resp.getheader('location', None)
|
||||
@ -180,7 +178,7 @@ class HTTPClient(object):
|
||||
raise exc.InvalidEndpoint(message=message)
|
||||
return self._http_request(location, method, **kwargs)
|
||||
elif resp.status == 300:
|
||||
raise exc.from_response(resp)
|
||||
raise exc.from_response(resp, body_iter)
|
||||
|
||||
return resp, body_iter
|
||||
|
||||
|
@ -34,20 +34,10 @@ class CommunicationError(BaseException):
|
||||
"""Unable to communicate with server."""
|
||||
|
||||
|
||||
class ClientException(Exception):
|
||||
"""DEPRECATED"""
|
||||
|
||||
|
||||
class HTTPException(ClientException):
|
||||
class HTTPException(BaseException):
|
||||
"""Base exception for all HTTP-derived exceptions"""
|
||||
code = 'N/A'
|
||||
|
||||
def __init__(self, details=None):
|
||||
self.details = details
|
||||
|
||||
def __str__(self):
|
||||
return "%s (HTTP %s)" % (self.__class__.__name__, self.code)
|
||||
|
||||
|
||||
class HTTPMultipleChoices(HTTPException):
|
||||
code = 300
|
||||
@ -147,10 +137,11 @@ for obj_name in dir(sys.modules[__name__]):
|
||||
_code_map[obj.code] = obj
|
||||
|
||||
|
||||
def from_response(response):
|
||||
def from_response(response, body_iter):
|
||||
"""Return an instance of an HTTPException based on httplib response."""
|
||||
cls = _code_map.get(response.status, HTTPException)
|
||||
return cls()
|
||||
body_str = ''.join([chunk for chunk in body_iter])
|
||||
return cls(body_str)
|
||||
|
||||
|
||||
class NoTokenLookupException(Exception):
|
||||
|
Loading…
Reference in New Issue
Block a user