diff --git a/openstack/exceptions.py b/openstack/exceptions.py index f449e86dd..e2b1ca309 100644 --- a/openstack/exceptions.py +++ b/openstack/exceptions.py @@ -211,6 +211,9 @@ def raise_from_response(response, error_message=None): try: content = response.json() messages = [_extract_message(obj) for obj in content.values()] + if not any(messages): + # Exception dict may be the root dict in projects that use WSME + messages = [_extract_message(content)] # Join all of the messages together nicely and filter out any # objects that don't have a "message" attr. details = '\n'.join(msg for msg in messages if msg) diff --git a/openstack/tests/unit/test_exceptions.py b/openstack/tests/unit/test_exceptions.py index a3286719c..cf2d74736 100644 --- a/openstack/tests/unit/test_exceptions.py +++ b/openstack/tests/unit/test_exceptions.py @@ -213,3 +213,21 @@ class TestRaiseFromResponse(base.TestCase): self.assertEqual(response.status_code, exc.status_code) self.assertEqual(self.message, exc.details) self.assertIn(self.message, str(exc)) + + def test_raise_wsme_format(self): + response = mock.Mock() + response.status_code = 404 + response.headers = { + 'content-type': 'application/json', + } + response.json.return_value = { + 'faultstring': self.message, + 'faultcode': 'Client', + 'debuginfo': None, + } + exc = self.assertRaises(exceptions.NotFoundException, + self._do_raise, response, + error_message=self.message) + self.assertEqual(response.status_code, exc.status_code) + self.assertEqual(self.message, exc.details) + self.assertIn(self.message, str(exc))