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.
This commit is contained in:
Tomas Sedovic 2012-03-21 17:24:53 +01:00
parent 8acb771bb9
commit faddc4daae
1 changed files with 5 additions and 1 deletions

View 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)