Created
July 1, 2020 03:58
-
-
Save pydanny/033f477ea314f7288a38e3b105a57ddb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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