From 19d542ef5f570d98e08008898a0ee31a3186d5a9 Mon Sep 17 00:00:00 2001 From: Ken'ichi Ohmichi Date: Tue, 1 Jan 2013 22:33:15 +0900 Subject: 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 --- glanceclient/exc.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'glanceclient/exc.py') diff --git a/glanceclient/exc.py b/glanceclient/exc.py index fe86591..d5adb92 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() -- cgit v1.2.1