Browse Source

Added a custom 500 handler to include exception details

Jeremy Stretch 8 years ago
parent
commit
23451fe974
3 changed files with 21 additions and 8 deletions
  1. 3 1
      netbox/netbox/urls.py
  2. 10 5
      netbox/netbox/views.py
  3. 8 2
      netbox/templates/500.html

+ 3 - 1
netbox/netbox/urls.py

@@ -2,10 +2,12 @@ from django.conf.urls import include, url
 from django.contrib import admin
 from django.views.defaults import page_not_found
 
-from views import home, trigger_500
+from views import home, trigger_500, handle_500
 from users.views import login, logout
 
 
+handler500 = handle_500
+
 urlpatterns = [
 
     # Default page

+ 10 - 5
netbox/netbox/views.py

@@ -1,9 +1,6 @@
-from markdown import markdown
+import sys
 
-from django.conf import settings
-from django.http import Http404
 from django.shortcuts import render
-from django.utils.safestring import mark_safe
 
 from circuits.models import Provider, Circuit
 from dcim.models import Site, Rack, Device, ConsolePort, PowerPort, InterfaceConnection
@@ -47,6 +44,14 @@ def home(request):
 
 def trigger_500(request):
     """Hot-wired method of triggering a server error to test reporting."""
-
     raise Exception("Congratulations, you've triggered an exception! Go tell all your friends what an exceptional "
                     "person you are.")
+
+
+def handle_500(request):
+    """Custom server error handler"""
+    type_, error, traceback = sys.exc_info()
+    return render(request, '500.html', {
+        'exception': str(type_),
+        'error': error,
+    }, status=500)

+ 8 - 2
netbox/templates/500.html

@@ -12,13 +12,19 @@
         <div class="col-md-4 col-md-offset-4">
             <div class="panel panel-danger" style="margin-top: 200px">
                 <div class="panel-heading">
-                    <strong>Server Error</strong>
+                    <strong>
+                        <i class="glyphicon glyphicon-warning-sign"></i>
+                        Server Error
+                    </strong>
                 </div>
                 <div class="panel-body">
                     <p>There was a problem with your request. This error has been logged and administrative staff have
                     been notified. Please return to the home page and try again.</p>
                     <p>If you are responsible for this installation, please consider
-                    <a href="https://github.com/digitalocean/netbox/issues">filing a bug report</a>.</p>
+                    <a href="https://github.com/digitalocean/netbox/issues">filing a bug report</a>. Additional
+                    information is provided below:</p>
+                    <pre><strong>{{ exception }}</strong><br />
+{{ error }}</pre>
                     <div class="text-right">
                         <a href="/" class="btn btn-primary">Home Page</a>
                     </div>