summaryrefslogtreecommitdiff
path: root/glanceclient/exc.py
diff options
context:
space:
mode:
authorKen'ichi Ohmichi <oomichi@mxs.nes.nec.co.jp>2013-01-01 22:33:15 +0900
committerKen'ichi Ohmichi <oomichi@mxs.nes.nec.co.jp>2013-01-01 22:33:15 +0900
commit19d542ef5f570d98e08008898a0ee31a3186d5a9 (patch)
tree6557bd2213f4640ad14eb3062bd75d2fa3695305 /glanceclient/exc.py
parentc057fe47d6889912b7675aa54102509cd464171a (diff)
downloadpython-glanceclient-19d542ef5f570d98e08008898a0ee31a3186d5a9.tar.gz
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
Diffstat (limited to 'glanceclient/exc.py')
-rw-r--r--glanceclient/exc.py10
1 files changed, 7 insertions, 3 deletions
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()