Get errors from Keystone-Moon and throw them from Moonclient 83/3483/1
authorasteroide <thomas.duval@orange.com>
Fri, 20 Nov 2015 15:04:31 +0000 (16:04 +0100)
committerasteroide <thomas.duval@orange.com>
Fri, 20 Nov 2015 15:04:31 +0000 (16:04 +0100)
Change-Id: I686f2d49b0c41a8352ed9c18805fbf4058d8ad3d

moonclient/moonclient/shell.py

index 49422a4..5e40bf4 100644 (file)
@@ -150,9 +150,21 @@ class MoonClient(App):
         content = resp.read()
         conn.close()
         try:
-            return json.loads(content)
+            content = json.loads(content)
+            if "error" in content:
+                try:
+                    raise Exception("Getting an error while requiring {} ({}: {}, {})".format(
+                        url,
+                        content['error']['code'],
+                        content['error']['title'],
+                        content['error']['message'],
+                    ))
+                except ValueError:
+                    raise Exception("Getting an error while requiring {} ({})".format(url, content))
+            return content
         except ValueError:
-            return {"content": content}
+            raise Exception("Getting an error while requiring {} ({})".format(url, content))
+            # return {"content": content}
 
     def auth_keystone(self, username=None, password=None, host=None, port=None):
         """Send a new authentication request to Keystone