summaryrefslogtreecommitdiff
path: root/novaclient/exceptions.py
diff options
context:
space:
mode:
Diffstat (limited to 'novaclient/exceptions.py')
-rw-r--r--novaclient/exceptions.py18
1 files changed, 15 insertions, 3 deletions
diff --git a/novaclient/exceptions.py b/novaclient/exceptions.py
index c502e964..31dd4871 100644
--- a/novaclient/exceptions.py
+++ b/novaclient/exceptions.py
@@ -294,9 +294,21 @@ def from_response(response, body, url, method=None):
details = "n/a"
if hasattr(body, 'keys'):
- error = body[list(body)[0]]
- message = error.get('message')
- details = error.get('details')
+ # NOTE(mriedem): WebOb<1.6.0 will return a nested dict structure
+ # where the error keys to the message/details/code. WebOb>=1.6.0
+ # returns just a response body as a single dict, not nested,
+ # so we have to handle both cases (since we can't trust what we're
+ # given with content_type: application/json either way.
+ if 'message' in body:
+ # WebOb 1.6.0 case
+ message = body.get('message')
+ details = body.get('details')
+ else:
+ # WebOb<1.6.0 where we assume there is a single error message
+ # key to the body that has the message and details.
+ error = body[list(body)[0]]
+ message = error.get('message')
+ details = error.get('details')
kwargs['message'] = message
kwargs['details'] = details