From faddc4daaebcefa4c92d7b8fe2f9c4ea8cf66633 Mon Sep 17 00:00:00 2001 From: Tomas Sedovic Date: Wed, 21 Mar 2012 17:24:53 +0100 Subject: [PATCH] Properly handle templates of invalid format Fixes #19 When we receive a template that's not in JSON, we display a meaningful message instead of a stacktrace. --- heat/api/v1/stacks.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/heat/api/v1/stacks.py b/heat/api/v1/stacks.py index 86761ced..4dca077a 100644 --- a/heat/api/v1/stacks.py +++ b/heat/api/v1/stacks.py @@ -114,7 +114,11 @@ class StackController(object): msg = _("TemplateBody or TemplateUrl were not given.") return webob.exc.HTTPBadRequest(explanation=msg) - stack = json.loads(templ) + try: + stack = json.loads(templ) + except ValueError: + msg = _("The Template must be a JSON document.") + return webob.exc.HTTPBadRequest(explanation=msg) stack['StackName'] = req.params['StackName'] return c.create_stack(stack) -- 2.45.2