Commit 4c85c0e6 by Őry Máté

dashboard: show unhandled HumanReadableExceptions on http500 page

parent 79712693
...@@ -64,3 +64,5 @@ if get_env_variable('DJANGO_SAML', 'FALSE') == 'TRUE': ...@@ -64,3 +64,5 @@ if get_env_variable('DJANGO_SAML', 'FALSE') == 'TRUE':
'', '',
(r'^saml2/', include('djangosaml2.urls')), (r'^saml2/', include('djangosaml2.urls')),
) )
handler500 = 'common.views.handler500'
from sys import exc_info
import logging
from django.template import RequestContext
from django.shortcuts import render_to_response
from .models import HumanReadableException
logger = logging.getLogger(__name__)
def handler500(request):
cls, exception, traceback = exc_info()
logger.exception("unhandled exception")
ctx = {}
if isinstance(exception, HumanReadableException):
try:
ctx['error'] = exception.get_user_text()
except:
pass
else:
try:
if request.user.is_superuser():
ctx['error'] = exception.get_admin_text()
except:
pass
try:
resp = render_to_response("500.html", ctx, RequestContext(request))
except:
resp = render_to_response("500.html", ctx)
resp.status_code = 500
return resp
{% extends "base.html" %} {% extends "dashboard/base.html" %}
{% load i18n %} {% load i18n %}
{% block title %}HTTP 500{% endblock %} {% block title %}HTTP 500{% endblock %}
...@@ -6,5 +6,11 @@ ...@@ -6,5 +6,11 @@
{% block page_title %}{% trans ":(" %}{% endblock page_title %} {% block page_title %}{% trans ":(" %}{% endblock page_title %}
{% block content %} {% block content %}
<div style="margin-top: 4em;">
{% if error %}
<p>{{ error }}</p>
{% else %}
<p>{% trans "Internal Server Error... Please leave the server alone..." %}</p> <p>{% trans "Internal Server Error... Please leave the server alone..." %}</p>
{% endif %}
</div>
{% endblock content %} {% endblock content %}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment