Browse Source

Handle error response for webob>=1.6.0

WebOb change https://github.com/Pylons/webob/pull/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:

https://github.com/Pylons/webob/issues/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
(cherry picked from commit 19befa6965)
Akira KAMIO 2 years ago
parent
commit
b20d9fd656
1 changed files with 8 additions and 3 deletions
  1. 8
    3
      cinderclient/exceptions.py

+ 8
- 3
cinderclient/exceptions.py View File

@@ -242,9 +242,14 @@ def from_response(response, body):
242 242
         message = "n/a"
243 243
         details = "n/a"
244 244
         if hasattr(body, 'keys'):
245
-            error = body[list(body)[0]]
246
-            message = error.get('message', message)
247
-            details = error.get('details', details)
245
+            # Only in webob>=1.6.0
246
+            if 'message' in body:
247
+                message = body.get('message')
248
+                details = body.get('details')
249
+            else:
250
+                error = body[list(body)[0]]
251
+                message = error.get('message', message)
252
+                details = error.get('details', details)
248 253
         return cls(code=response.status_code, message=message, details=details,
249 254
                    request_id=request_id, response=response)
250 255
     else:

Loading…
Cancel
Save