@@ -515,11 +515,22 @@ def inner_main(self):
515515 self .error_message .append (self ._ ('Form Error: ' ) + str (e ))
516516 self .write_html (self .renderContext ())
517517 except :
518- if self .instance .config .WEB_DEBUG :
519- self .write_html (cgitb .html (i18n = self .translator ))
518+ # Something has gone badly wrong. Therefore, we should
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 ))
520532 else :
521- self .mailer .exception_message ()
522- return self .write_html (self ._ (error_message ))
533+ self .write_html (html )
523534
524535 def clean_sessions (self ):
525536 """Deprecated
@@ -950,6 +961,17 @@ def _serve_file(self, lmt, mime_type, content=None, filename=None):
950961 self .additional_headers ['Content-Length' ] = str (len (content ))
951962 self .write (content )
952963
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+
953975 def renderContext (self ):
954976 """ Return a PageTemplate for the named page
955977 """
@@ -996,16 +1018,8 @@ def renderContext(self):
9961018 try :
9971019 # If possible, send the HTML page template traceback
9981020 # to the administrator.
999- to = [self .mailer .config .ADMIN_EMAIL ]
10001021 subject = "Templating Error: %s" % exc_info [1 ]
1001- content = 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 ))
1022+ self .send_html_to_admin (subject , cgitb .pt_html ())
10091023 # Now report the error to the user.
10101024 return self ._ (error_message )
10111025 except :
0 commit comments