diff roundup/cgi/client.py @ 6382:b35a50d02890

Fix issue2551129 - Template not found return 500 and traceback Handle traceback caused when requested @template is not found. Moved scope of try to include call to self.selectTemplate. Patch provided by Cedric Krier. Additional patch to make this case return 400 error since it is a client caused error. Test case added.
author John Rouillard <rouilj@ieee.org>
date Sun, 18 Apr 2021 20:54:48 -0400
parents 7b6a02611a77
children 1f2f7c0b8968
line wrap: on
line diff
--- a/roundup/cgi/client.py	Sun Apr 18 19:28:12 2021 -0400
+++ b/roundup/cgi/client.py	Sun Apr 18 20:54:48 2021 -0400
@@ -1863,14 +1863,14 @@
     def renderContext(self):
         """ Return a PageTemplate for the named page
         """
-        tplname = self.selectTemplate(self.classname, self.template)
+        try:
+            tplname = self.selectTemplate(self.classname, self.template)
 
-        # catch errors so we can handle PT rendering errors more nicely
-        args = {
-            'ok_message': self._ok_message,
-            'error_message': self._error_message
-        }
-        try:
+            # catch errors so we can handle PT rendering errors more nicely
+            args = {
+                'ok_message': self._ok_message,
+                'error_message': self._error_message
+            }
             pt = self.instance.templates.load(tplname)
             # let the template render figure stuff out
             result = pt.render(self, None, None, **args)
@@ -1894,6 +1894,7 @@
                 result = result.replace('</body>', s)
             return result
         except templating.NoTemplate as message:
+            self.response_code = 400 
             return '<strong>%s</strong>'%html_escape(str(message))
         except templating.Unauthorised as message:
             raise Unauthorised(html_escape(str(message)))

Roundup Issue Tracker: http://roundup-tracker.org/