Skip to content

Commit

Permalink
Added a custom 500 handler to include exception details
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremystretch committed Jul 15, 2016
1 parent 5def0e9 commit 23451fe
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
4 changes: 3 additions & 1 deletion netbox/netbox/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
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
Expand Down
15 changes: 10 additions & 5 deletions netbox/netbox/views.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
10 changes: 8 additions & 2 deletions netbox/templates/500.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down

0 comments on commit 23451fe

Please sign in to comment.