def send_error_mail(exception):
"""Sends an error mail to the admin containing the traceback and configuration.
After that, a custom HTTP 500 page is shown.
:param exception: the exception raised
:type exception: ``Exception``
:return:
the HTML to send back in the response, and the HTTP code 500.
:rtype: str, int
"""
# Inspired from <https://github.com/jasonwyatt/Flask-ErrorMail>.
message = Message("Join2 ORCID exception: %s" % exception, sender=CFG_SITE_ADMIN_EMAIL,
recipients=[CFG_SITE_ADMIN_EMAIL])
message_contents = ["Traceback:", "=" * 80, traceback.format_exc(), "\n", "Request Information:", "=" * 80]
environ = request.environ
for key in sorted(environ.keys()):
message_contents.append("%s: %s" % (key, environ.get(key)))
message.body = "\n".join(message_contents) + "\n"
mailer.send(message)
return render_template("500.html"), 500
评论列表
文章目录