Skip to content

Commit

Permalink
Handle error response for webob>=1.6.0
Browse files Browse the repository at this point in the history
WebOb change Pylons/webob#230 changed
the way in which the error response body is formatted such that
it's no longer a nested dict. So we have to handle both the
old convention of an error message key to the response body error
dict and the new way with just the error body dict.

This was reported upstream:

Pylons/webob#235

But given this was apparently implemented as a long-overdue change
in WebOb the behavior is not likely to change.Handle error response for
webob>=1.6.0

Change-Id: I7d589415aa024588faf77c8234ac026110f6c3cd
Closes-Bug: #1559072
  • Loading branch information
Akira KAMIO committed Dec 9, 2016
1 parent 0405d39 commit 19befa6
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions cinderclient/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,14 @@ def from_response(response, body):
message = "n/a"
details = "n/a"
if hasattr(body, 'keys'):
error = body[list(body)[0]]
message = error.get('message', message)
details = error.get('details', details)
# Only in webob>=1.6.0
if 'message' in body:
message = body.get('message')
details = body.get('details')
else:
error = body[list(body)[0]]
message = error.get('message', message)
details = error.get('details', details)
return cls(code=response.status_code, message=message, details=details,
request_id=request_id, response=response)
else:
Expand Down

0 comments on commit 19befa6

Please sign in to comment.