From 8a572c0b887a58df9bace67d567337a08ba3af18 Mon Sep 17 00:00:00 2001 From: Zane Bitter Date: Mon, 21 Jan 2013 16:36:21 +0100 Subject: [PATCH] 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 --- heat/common/wsgi.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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): -- 2.45.2