1 2 3 4 5 6 7 8 9 10 | from django.http import HttpResponseRedirect
class HttpMessageMiddleware(object):
def process_exception(self, request, exception):
if request.user.is_authenticated():
request.user.message_set.create(message=unicode(exception))
return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/'))
class HttpMessage(Exception):
pass
|
More like this
- PermanentRedirectMiddleware by marinho 4 years, 9 months ago
- View decorator to convert DoesNotExist (ObjectDoesNotExist) exceptions into Http404 exceptions by jammycakes 3 years, 7 months ago
- A custom 500 handler which is AJAX-aware by mallipeddi 5 years, 3 months ago
- Cookie based flash errors and notices (a la Rails) by alexk 4 years, 8 months ago
- Middleware to move tags <script> to the bottom by marinho 2 years, 10 months ago
Comments
It can go in infinite loop. May be some query string parameter can be used to circumvent that.
#
This recipe catches all errors. "except HttpMessage" is missing in process_exception().
#