Mercurial > p > roundup > code
diff roundup/cgi/client.py @ 5165:a86860224d80
issue2550755: exceptions.NotFound(msg) msg is not reported to user in cgi.
When an invalid column is specified return error code 400 rather than
404. Make error code 400 also return an error message to the
user. Reported by: Bernhard Reiter.
After I implemented this it occurred to me that this may be better
implemented using a new exception BadRequest and handle that
instead. I really don't have a good feel for which is better from an
architectural view although I have a feeling the exception path would
be better.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Mon, 15 Aug 2016 20:53:37 -0400 |
| parents | f608eeecf638 |
| children | 232c74973a56 |
line wrap: on
line diff
--- a/roundup/cgi/client.py Sat Jul 23 17:21:14 2016 -0400 +++ b/roundup/cgi/client.py Mon Aug 15 20:53:37 2016 -0400 @@ -550,16 +550,32 @@ self.response_code = 304 self.header() except NotFound, e: - self.response_code = 404 - self.template = '404' - try: - cl = self.db.getclass(self.classname) - self.write_html(self.renderContext()) - except KeyError: - # we can't map the URL to a class we know about - # reraise the NotFound and let roundup_server - # handle it - raise NotFound(e) + if self.response_code == 400: + # We can't find a parameter (e.g. property name + # incorrect). Tell the user what was raised. + # Do not change to the 404 template since the + # base url is valid just query args are not. + # copy the page format from SeriousError _str_ exception. + error_page = """ + <html><head><title>Roundup issue tracker: An error has occurred</title> + <link rel="stylesheet" type="text/css" href="@@file/style.css"> + </head> + <body class="body" marginwidth="0" marginheight="0"> + <p class="error-message">%s</p> + </body></html> + """ + self.write_html(error_page%str(e)) + else: + self.response_code = 404 + self.template = '404' + try: + cl = self.db.getclass(self.classname) + self.write_html(self.renderContext()) + except KeyError: + # we can't map the URL to a class we know about + # reraise the NotFound and let roundup_server + # handle it + raise NotFound(e) except FormError, e: self.add_error_message(self._('Form Error: ') + str(e)) self.write_html(self.renderContext())
