Message exception

 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

  1. Message Exception by mulamvenky 11 months, 1 week ago
  2. Mask sensitive POST fields in error e-mails by derivin 6 years, 1 month ago
  3. Doing redirect without request by diverman 3 years, 6 months ago
  4. Severity codes in user messages by cconnell 5 years, 3 months ago
  5. keywords arguments parser for custom template tags by bruno 5 years, 2 months ago

Comments

amitu (on October 15, 2008):

It can go in infinite loop. May be some query string parameter can be used to circumvent that.

#

guettli (on October 30, 2008):

This recipe catches all errors. "except HttpMessage" is missing in process_exception().

#

(Forgotten your password?)