diff --git a/glanceclient/common/http.py b/glanceclient/common/http.py index f905b0d3..1a5ce204 100644 --- a/glanceclient/common/http.py +++ b/glanceclient/common/http.py @@ -177,7 +177,7 @@ class HTTPClient(object): if 400 <= resp.status < 600: LOG.error("Request returned failure status.") - raise exc.from_response(resp) + raise exc.from_response(resp, body_str) elif resp.status in (301, 302, 305): # Redirected. Reissue the request to the new location. return self._http_request(resp['location'], method, **kwargs) diff --git a/glanceclient/exc.py b/glanceclient/exc.py index fe86591f..d5adb92d 100644 --- a/glanceclient/exc.py +++ b/glanceclient/exc.py @@ -46,10 +46,10 @@ class HTTPException(ClientException): code = 'N/A' def __init__(self, details=None): - self.details = details + self.details = details or self.__class__.__name__ def __str__(self): - return "%s (HTTP %s)" % (self.__class__.__name__, self.code) + return "%s (HTTP %s)" % (self.details, self.code) class HTTPMultipleChoices(HTTPException): @@ -150,9 +150,13 @@ for obj_name in dir(sys.modules[__name__]): _code_map[obj.code] = obj -def from_response(response): +def from_response(response, body=None): """Return an instance of an HTTPException based on httplib response.""" cls = _code_map.get(response.status, HTTPException) + if body: + details = body.replace('\n\n', '\n') + return cls(details=details) + return cls()