]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mgr/dashboard_v2: Added test_restresource.py
authorSebastian Wagner <sebastian.wagner@suse.com>
Thu, 25 Jan 2018 10:27:07 +0000 (11:27 +0100)
committerRicardo Dias <rdias@suse.com>
Mon, 5 Mar 2018 13:06:59 +0000 (13:06 +0000)
Signed-off-by: Sebastian Wagner <sebastian.wagner@suse.com>
src/pybind/mgr/dashboard_v2/restresource.py

index 068b031e023111944610d715d3d79ad784319880..ecbd5c4b1d4b86861eaf8fabd289258e48cc1852 100644 (file)
@@ -5,12 +5,14 @@ import cherrypy
 
 def _takes_json(func):
     def inner(*args, **kwargs):
-        body = cherrypy.request.body.read()
+        content_length = int(cherrypy.request.headers['Content-Length'])
+        body = cherrypy.request.body.read(content_length)
+        if not body:
+            raise cherrypy.HTTPError(400, 'Empty body. Content-Length={}'.format(content_length))
         try:
             data = json.loads(body.decode('utf-8'))
-        except json.JSONDecodeError as e:
-            raise cherrypy.HTTPError(400, 'Failed to decode JSON: {}'
-                                          .format(str(e)))
+        except Exception as e:
+            raise cherrypy.HTTPError(400, 'Failed to decode JSON: {}'.format(str(e)))
         return func(data, *args, **kwargs)
     return inner