Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add details to stdout error message.
Current glance command does not show the details of error message.
For example, the glance command shows HTTPBadRequest only if some
necessary parameter is not specified.

 $ glance image-create --file root-fs.img --name cirros-0.3.0-x86_64-uec
 Request returned failure status.
 HTTPBadRequest (HTTP 400)
 $

By only the above message, it is not easy that a user understand the reason
of an error. glance-api server returns the details of reason, but glance
command does not show it.

This patch adds details, which is gotten from glance-api server, to error
message. And a user will be able to understand the reason of a error like
the following:

 $ glance image-create --file root-fs.img --name cirros-0.3.0-x86_64-uec
 Request returned failure status.
 400 Bad Request
 Invalid disk format 'None' for image.
     (HTTP 400)
 $

Fixes bug 1094917

Change-Id: I49192c3ebbc8a70b63dcfcede9fd13f1688388cf
  • Loading branch information
Ken'ichi Ohmichi committed Jan 1, 2013
1 parent c057fe4 commit 19d542e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion glanceclient/common/http.py
Expand Up @@ -177,7 +177,7 @@ def _http_request(self, url, method, **kwargs):

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)
Expand Down
10 changes: 7 additions & 3 deletions glanceclient/exc.py
Expand Up @@ -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):
Expand Down Expand Up @@ -150,9 +150,13 @@ class HTTPServiceUnavailable(ServiceUnavailable):
_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()


Expand Down

0 comments on commit 19d542e

Please sign in to comment.