Skip to content

Instantly share code, notes, and snippets.

@pydanny
Created July 1, 2020 03:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pydanny/033f477ea314f7288a38e3b105a57ddb to your computer and use it in GitHub Desktop.
Save pydanny/033f477ea314f7288a38e3b105a57ddb to your computer and use it in GitHub Desktop.
import sys
from django.core.signals import got_request_exception
from django.core.urlresolvers import reverse
from django.views.debug import technical_500_response
from django.utils.deprecation import MiddlewareMixin
class UserBasedExceptionMiddleware(MiddlewareMixin):
"""Allows superusers to see 500 debug pages in production"""
def process_request(self, request):
pass
def process_exception(self, request, exception):
# Make sure the exception signal is fired for Sentry
got_request_exception.send(sender=self, request=request)
if request.user.is_superuser:
return technical_500_response(request, *sys.exc_info())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment