Fix Bug 934. OSM CLI crashes for listing operations with insufficient permissions
[osm/osmclient.git] / osmclient / sol005 / repo.py
index a8d8f17..1f487de 100644 (file)
@@ -17,6 +17,7 @@ OSM Repo API handling
 """
 
 from osmclient.common import utils
+from osmclient.common.exceptions import OsmHttpException
 from osmclient.common.exceptions import ClientException
 from osmclient.common.exceptions import NotFound
 import json
@@ -37,21 +38,21 @@ class Repo(object):
                                        postfields_dict=repo)
         #print 'HTTP CODE: {}'.format(http_code)
         #print 'RESP: {}'.format(resp)
-        if http_code in (200, 201, 202, 204):
-            if resp:
-                resp = json.loads(resp)
-            if not resp or 'id' not in resp:
-                raise ClientException('unexpected response from server - {}'.format(
-                                      resp))
-            print(resp['id'])
-        else:
-            msg = ""
-            if resp:
-                try:
-                    msg = json.loads(resp)
-                except ValueError:
-                    msg = resp
-            raise ClientException("failed to add repo {} - {}".format(name, msg))
+        #if http_code in (200, 201, 202, 204):
+        if resp:
+            resp = json.loads(resp)
+        if not resp or 'id' not in resp:
+            raise OsmHttpException('unexpected response from server - {}'.format(
+                                  resp))
+        print(resp['id'])
+        #else:
+        #    msg = ""
+        #    if resp:
+        #        try:
+        #            msg = json.loads(resp)
+        #        except ValueError:
+        #            msg = resp
+        #    raise ClientException("failed to add repo {} - {}".format(name, msg))
 
     def update(self, name, repo):
         self._client.get_token()
@@ -60,16 +61,16 @@ class Repo(object):
                                        postfields_dict=repo)
         # print 'HTTP CODE: {}'.format(http_code)
         # print 'RESP: {}'.format(resp)
-        if http_code in (200, 201, 202, 204):
-            pass
-        else:
-            msg = ""
-            if resp:
-                try:
-                    msg = json.loads(resp)
-                except ValueError:
-                    msg = resp
-            raise ClientException("failed to update repo {} - {}".format(name, msg))
+        #if http_code in (200, 201, 202, 204):
+        #    pass
+        #else:
+        #    msg = ""
+        #    if resp:
+        #        try:
+        #            msg = json.loads(resp)
+        #        except ValueError:
+        #            msg = resp
+        #    raise ClientException("failed to update repo {} - {}".format(name, msg))
 
     def get_id(self, name):
         """Returns a repo id from a repo name
@@ -112,9 +113,9 @@ class Repo(object):
         filter_string = ''
         if filter:
             filter_string = '?{}'.format(filter)
-        resp = self._http.get_cmd('{}{}'.format(self._apiBase,filter_string))
+        _, resp = self._http.get2_cmd('{}{}'.format(self._apiBase,filter_string))
         if resp:
-            return resp
+            return json.loads(resp)
         return list()
 
     def get(self, name):
@@ -124,10 +125,11 @@ class Repo(object):
         repo_id = name
         if not utils.validate_uuid4(name):
             repo_id = self.get_id(name)
-        resp = self._http.get_cmd('{}/{}'.format(self._apiBase,repo_id))
-        if not resp or '_id' not in resp:
-            raise ClientException('failed to get repo info: '.format(resp))
-        else:
-            return resp
+        _, resp = self._http.get2_cmd('{}/{}'.format(self._apiBase,repo_id))
+#        if not resp or '_id' not in resp:
+#            raise ClientException('failed to get repo info: '.format(resp))
+#        else:
+        if resp:
+            return json.loads(resp)
         raise NotFound("Repo {} not found".format(name))