comparison 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
comparison
equal deleted inserted replaced
6381:89aa919997c0 6382:b35a50d02890
1861 tplname, generic)) 1861 tplname, generic))
1862 1862
1863 def renderContext(self): 1863 def renderContext(self):
1864 """ Return a PageTemplate for the named page 1864 """ Return a PageTemplate for the named page
1865 """ 1865 """
1866 tplname = self.selectTemplate(self.classname, self.template)
1867
1868 # catch errors so we can handle PT rendering errors more nicely
1869 args = {
1870 'ok_message': self._ok_message,
1871 'error_message': self._error_message
1872 }
1873 try: 1866 try:
1867 tplname = self.selectTemplate(self.classname, self.template)
1868
1869 # catch errors so we can handle PT rendering errors more nicely
1870 args = {
1871 'ok_message': self._ok_message,
1872 'error_message': self._error_message
1873 }
1874 pt = self.instance.templates.load(tplname) 1874 pt = self.instance.templates.load(tplname)
1875 # let the template render figure stuff out 1875 # let the template render figure stuff out
1876 result = pt.render(self, None, None, **args) 1876 result = pt.render(self, None, None, **args)
1877 self.additional_headers['Content-Type'] = pt.content_type 1877 self.additional_headers['Content-Type'] = pt.content_type
1878 if self.env.get('CGI_SHOW_TIMING', ''): 1878 if self.env.get('CGI_SHOW_TIMING', ''):
1892 "%(endtag)s\n") % timings 1892 "%(endtag)s\n") % timings
1893 s += '</body>' 1893 s += '</body>'
1894 result = result.replace('</body>', s) 1894 result = result.replace('</body>', s)
1895 return result 1895 return result
1896 except templating.NoTemplate as message: 1896 except templating.NoTemplate as message:
1897 self.response_code = 400
1897 return '<strong>%s</strong>'%html_escape(str(message)) 1898 return '<strong>%s</strong>'%html_escape(str(message))
1898 except templating.Unauthorised as message: 1899 except templating.Unauthorised as message:
1899 raise Unauthorised(html_escape(str(message))) 1900 raise Unauthorised(html_escape(str(message)))
1900 except: 1901 except:
1901 # everything else 1902 # everything else

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