]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
Properly handle templates of invalid format
authorTomas Sedovic <tomas@sedovic.cz>
Wed, 21 Mar 2012 16:24:53 +0000 (17:24 +0100)
committerTomas Sedovic <tomas@sedovic.cz>
Wed, 21 Mar 2012 16:24:53 +0000 (17:24 +0100)
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

index 86761cedb3bc27e86ad6f11827d3ada67ad00df5..4dca077a6f759caf7d78b2e9b01f2fc40c5d19a1 100644 (file)
@@ -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)