def process_exception(self, suppressed_exceptions=None):
exception_name = sys.exc_info()[0].__name__
exception_details = str(sys.exc_info()[1])
exception_traceback = ''.join(traceback.format_exception(*sys.exc_info()))
logging.error(exception_traceback)
send_email = not (suppressed_exceptions and exception_name in suppressed_exceptions)
if send_email:
exception_expiration = 3600 # seconds (max 1 mail per hour for a particular exception)
mail_admin = SENDER_EMAIL # must be admin for the application
sitename = SITENAME
ver = os.environ['CURRENT_VERSION_ID']
dev = any(keyword in ver for keyword in TEST_VERSIONS) or tools.on_dev_server()
sitename += ":DEV" if dev else ":PROD"
session = self.session
ename = "Unknown Org"
if session and session.has_key('enterprise'):
ename = session['enterprise'].name
throttle_name = 'exception-' + exception_name
throttle = memcache.get(throttle_name)
if throttle is None and not dev:
memcache.add(throttle_name, 1, exception_expiration)
subject = '[%s] exception for %s [%s: %s]' % (sitename, ename, exception_name, exception_details)
body = exception_traceback + "\n\n" + self.request.uri
mail.send_mail(to=ERROR_EMAIL, sender=mail_admin,
subject=subject,
body=body)
return exception_name, exception_details, exception_traceback
评论列表
文章目录