comparison roundup/cgi/client.py @ 4264:b1e614c6759f

Improve error reporting.
author Stefan Seefeld <stefan@seefeld.name>
date Fri, 09 Oct 2009 13:13:32 +0000
parents bd000a1e9a57
children e24a6ca34448
comparison
equal deleted inserted replaced
4263:bd000a1e9a57 4264:b1e614c6759f
513 raise NotFound, e 513 raise NotFound, e
514 except FormError, e: 514 except FormError, e:
515 self.error_message.append(self._('Form Error: ') + str(e)) 515 self.error_message.append(self._('Form Error: ') + str(e))
516 self.write_html(self.renderContext()) 516 self.write_html(self.renderContext())
517 except: 517 except:
518 if self.instance.config.WEB_DEBUG: 518 # Something has gone badly wrong. Therefore, we should
519 self.write_html(cgitb.html(i18n=self.translator)) 519 # make sure that the response code indicates failure.
520 if self.response_code == httplib.OK:
521 self.response_code = httplib.INTERNAL_SERVER_ERROR
522 # Help the administrator work out what went wrong.
523 html = ("<h1>Traceback</h1>"
524 + cgitb.html(i18n=self.translator)
525 + ("<h1>Environment Variables</h1><table>%s</table>"
526 % cgitb.niceDict("", self.env)))
527 if not self.instance.config.WEB_DEBUG:
528 exc_info = sys.exc_info()
529 subject = "Error: %s" % exc_info[1]
530 self.send_html_to_admin(subject, html)
531 self.write_html(self._(error_message))
520 else: 532 else:
521 self.mailer.exception_message() 533 self.write_html(html)
522 return self.write_html(self._(error_message))
523 534
524 def clean_sessions(self): 535 def clean_sessions(self):
525 """Deprecated 536 """Deprecated
526 XXX remove 537 XXX remove
527 """ 538 """
948 self.write_file(filename) 959 self.write_file(filename)
949 else: 960 else:
950 self.additional_headers['Content-Length'] = str(len(content)) 961 self.additional_headers['Content-Length'] = str(len(content))
951 self.write(content) 962 self.write(content)
952 963
964 def send_html_to_admin(self, subject, content):
965
966 to = [self.mailer.config.ADMIN_EMAIL]
967 message = self.mailer.get_standard_message(to, subject)
968 # delete existing content-type headers
969 del message['Content-type']
970 message['Content-type'] = 'text/html; charset=utf-8'
971 message.set_payload(content)
972 encode_quopri(message)
973 self.mailer.smtp_send(to, str(message))
974
953 def renderContext(self): 975 def renderContext(self):
954 """ Return a PageTemplate for the named page 976 """ Return a PageTemplate for the named page
955 """ 977 """
956 name = self.classname 978 name = self.classname
957 extension = self.template 979 extension = self.template
994 return cgitb.pt_html(i18n=self.translator) 1016 return cgitb.pt_html(i18n=self.translator)
995 exc_info = sys.exc_info() 1017 exc_info = sys.exc_info()
996 try: 1018 try:
997 # If possible, send the HTML page template traceback 1019 # If possible, send the HTML page template traceback
998 # to the administrator. 1020 # to the administrator.
999 to = [self.mailer.config.ADMIN_EMAIL]
1000 subject = "Templating Error: %s" % exc_info[1] 1021 subject = "Templating Error: %s" % exc_info[1]
1001 content = cgitb.pt_html() 1022 self.send_html_to_admin(subject, cgitb.pt_html())
1002 message = self.mailer.get_standard_message(to, subject)
1003 # delete existing content-type headers
1004 del message['Content-type']
1005 message['Content-type'] = 'text/html; charset=utf-8'
1006 message.set_payload(content)
1007 encode_quopri(message)
1008 self.mailer.smtp_send(to, str(message))
1009 # Now report the error to the user. 1023 # Now report the error to the user.
1010 return self._(error_message) 1024 return self._(error_message)
1011 except: 1025 except:
1012 # Reraise the original exception. The user will 1026 # Reraise the original exception. The user will
1013 # receive an error message, and the adminstrator will 1027 # receive an error message, and the adminstrator will

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