Attempt to handle errors gracefully.
authorDirkjan Ochtman <dirkjan@ochtman.nl>
Wed, 06 Aug 2008 15:54:40 +0200
changeset 40 ef3a130e1e1487f57d2b4c17ead34830fb702b55
parent 39 8d8e307c084ed50e7969aaa7b91b199a71c1ed97
child 41 b582a89089e0315fc81c04c80dbd0d121e3520a3
push id15
push usertmielczarek@mozilla.com
push dateWed, 13 Aug 2008 19:07:41 +0000
Attempt to handle errors gracefully.
hgwebjson.py
--- a/hgwebjson.py
+++ b/hgwebjson.py
@@ -71,16 +71,19 @@ def tags(web, req, tmpl):
                               for tag, node in web.repo.tagslist()])
 
 addwebcommand(tags, 'webtags')
 
 def family(web, req, tmpl):
     """Get all the changesets related to a particular node, both children and
     parents, by walking backwards/forwards to a limit."""
 
+    if 'node' not in req.form:
+        return tmpl('error', error={'error': "missing parameter 'node'"})
+
     node = req.form['node'][0]
     ctx = web.repo.changectx(node)
 
     try:
         limit = int(req.form['limit'][0])
     except KeyError:
         limit = 2
 
@@ -103,12 +106,14 @@ def family(web, req, tmpl):
     parents(ctx, 1)
     return tmpl('family', family={'context': hex(ctx.node()),
                                   'nodes': nodelist})
 
 addwebcommand(family, 'family')
 
 def info(web, req, tmpl):
     """Get JSON information about the specified nodes."""
+    if 'node' not in req.form:
+        return tmpl('error', error={'error': "missing parameter 'node'"})
     nodes = dict((n, web.repo.changectx(n)) for n in req.form['node'])
     return tmpl('info', nodes=nodes)
 
 addwebcommand(info, 'info')