From: Zane Bitter Date: Mon, 21 Jan 2013 15:36:21 +0000 (+0100) Subject: ReST API: Return 400 for malformed JSON input X-Git-Tag: 2014.1~983^2 X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=8a572c0b887a58df9bace67d567337a08ba3af18;p=openstack-build%2Fheat-build.git ReST API: Return 400 for malformed JSON input Previously we had an unhandled exception that resulted in a 500 (Internal Server Error) result and a stack trace when an invalid JSON file was submitted in a POST/PUT request. Change to catching the exception and returning a 400 (Bad Request) result. bug 1102391 Change-Id: I7dde33ae732d9addbf988b1d36d4f06eacb634bf Signed-off-by: Zane Bitter --- diff --git a/heat/common/wsgi.py b/heat/common/wsgi.py index 02a046dc..0970e060 100644 --- a/heat/common/wsgi.py +++ b/heat/common/wsgi.py @@ -436,7 +436,10 @@ class JSONRequestDeserializer(object): return False def from_json(self, datastring): - return json.loads(datastring) + try: + return json.loads(datastring) + except ValueError as ex: + raise webob.exc.HTTPBadRequest(str(ex)) def default(self, request): if self.has_body(request):