From: Tomas Sedovic Date: Wed, 21 Mar 2012 16:24:53 +0000 (+0100) Subject: Properly handle templates of invalid format X-Git-Tag: 2014.1~2171 X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=faddc4daaebcefa4c92d7b8fe2f9c4ea8cf66633;p=openstack-build%2Fheat-build.git 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. --- 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)