aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy Doan <andy.doan@linaro.org>2015-04-16 15:13:02 +0000
committerLinaro Code Review <review@review.linaro.org>2015-04-16 15:13:02 +0000
commit7efa10484b9d841ac2ef43dc420f02edb9ed4bf0 (patch)
tree7256080300e15603d944e493cd5fea52eb2dc90c
parentc6a9445dd05677a3825835298b033d785158d3de (diff)
parentbbae70f401039ec96c919270d2a853a5e2916731 (diff)
Merge "handle 500 errors properly"
-rw-r--r--license_protected_downloads/views.py16
-rw-r--r--templates/500.html5
-rw-r--r--urls.py2
3 files changed, 23 insertions, 0 deletions
diff --git a/license_protected_downloads/views.py b/license_protected_downloads/views.py
index da3c24b..302ae0b 100644
--- a/license_protected_downloads/views.py
+++ b/license_protected_downloads/views.py
@@ -3,6 +3,7 @@ import json
import mimetypes
import os
import re
+import sys
from django.conf import settings
from django.http import (
@@ -378,3 +379,18 @@ def render_descriptions(path):
comment.data.strip())
return text
+
+
+def error_view(request, template_name='500.html'):
+ # the django error handler doesn't use the request context. We need this
+ # because it sets the 'base_page' variable required for our template
+ # to work across different "publishing themes"
+
+ # produce an error message like:
+ # RuntimeError at <path>/license_protected_downloads/views.py:228
+ ex, _, tb = sys.exc_info()
+ while tb.tb_next:
+ tb = tb.tb_next
+ ex = '%s at %s:%d' % (
+ ex.__name__, tb.tb_frame.f_code.co_filename, tb.tb_lineno)
+ return render(request, template_name, {'exception': ex}, status=500)
diff --git a/templates/500.html b/templates/500.html
index 6094529..727ea9c 100644
--- a/templates/500.html
+++ b/templates/500.html
@@ -2,4 +2,9 @@
{% block content %}
Server error.
+{% if exception %}
+<pre>
+{{exception}}
+</pre>
+{% endif %}
{% endblock %}
diff --git a/urls.py b/urls.py
index 06d3d9e..8399ee9 100644
--- a/urls.py
+++ b/urls.py
@@ -69,3 +69,5 @@ urlpatterns = patterns(
# This handler does that.
url(r'(?P<path>.*)', 'license_protected_downloads.views.file_server'),
)
+
+handler500 = 'license_protected_downloads.views.error_view'