|
|
@ -1,5 +1,10 @@ |
|
|
|
''' display error pages ''' |
|
|
|
''' display error pages ''' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import io |
|
|
|
|
|
|
|
import pprint |
|
|
|
|
|
|
|
import traceback |
|
|
|
|
|
|
|
import sys |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from pyramid.exceptions import BadCSRFToken |
|
|
|
from pyramid.exceptions import BadCSRFToken |
|
|
|
from pyramid.view import ( |
|
|
|
from pyramid.view import ( |
|
|
@ -7,6 +12,8 @@ from pyramid.view import ( |
|
|
|
forbidden_view_config, |
|
|
|
forbidden_view_config, |
|
|
|
view_config |
|
|
|
view_config |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
from pyramid_mailer.message import Message |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@notfound_view_config(renderer='ordr2:templates/errors/not_found.jinja2') |
|
|
|
@notfound_view_config(renderer='ordr2:templates/errors/not_found.jinja2') |
|
|
@ -38,6 +45,34 @@ def bad_csrf_view(context, request): |
|
|
|
renderer='ordr2:templates/errors/exception.jinja2' |
|
|
|
renderer='ordr2:templates/errors/exception.jinja2' |
|
|
|
) |
|
|
|
) |
|
|
|
def exception_view(context, request): |
|
|
|
def exception_view(context, request): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exc_type, exc_value, exc_traceback = sys.exc_info() |
|
|
|
|
|
|
|
traceback_output = io.StringIO() |
|
|
|
|
|
|
|
traceback.print_exc(file=traceback_output) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
request_output = io.StringIO() |
|
|
|
|
|
|
|
pprint.pprint(request.__dict__, stream=request_output) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
settings = request.registry.settings |
|
|
|
|
|
|
|
default_sender = settings['mail.default_sender'] |
|
|
|
|
|
|
|
recipient = settings.get('admin_email', None) or default_sender |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
body = '\n'.join([ |
|
|
|
|
|
|
|
traceback_output.getvalue(), |
|
|
|
|
|
|
|
'', |
|
|
|
|
|
|
|
'', |
|
|
|
|
|
|
|
'Request:', |
|
|
|
|
|
|
|
request_output.getvalue() |
|
|
|
|
|
|
|
]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
message = Message( |
|
|
|
|
|
|
|
subject='[ordr] Exception occured', |
|
|
|
|
|
|
|
sender=default_sender, |
|
|
|
|
|
|
|
recipients=[recipient], |
|
|
|
|
|
|
|
body=body |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
request.mailer.send_immediately(message) |
|
|
|
|
|
|
|
|
|
|
|
context.nav_highlight = 'errors' |
|
|
|
context.nav_highlight = 'errors' |
|
|
|
request.response.status = 500 |
|
|
|
request.response.status = 500 |
|
|
|
return {} |
|
|
|
return {} |
|
|
|