Commits

João Pedro Francese  committed 9f8428f

[v0.2.14] Added ExceptionUserInfoMiddleware

  • Participants
  • Parent commits dc97722

Comments (0)

Files changed (2)

File inoa/middleware/exception_user_info.py

+# -*- coding: utf-8 -*-
+
+
+class ExceptionUserInfoMiddleware(object):
+    """
+    Adds user details to request context on receiving an exception, so that they show up in the error emails.
+    Based on: https://gist.github.com/sidmitra/646372
+    
+    Add to settings.MIDDLEWARE_CLASSES and keep it outermost (i.e. on top if possible). 
+    This allows it to catch exceptions in other middlewares as well.
+    """
+    
+    def process_exception(self, request, exception):
+        try:
+            if request.user.is_authenticated():
+                request.META['USER_ID'] = str(request.user.id)
+                request.META['USER_NAME'] = str(request.user.username)
+                request.META['USER_EMAIL'] = str(request.user.email)
+        except:
+            pass
 
 setup(
     name='django-inoa',
-    version='0.2.13',
+    version='0.2.14',
     author='Inoa',
     author_email='django@inoa.com.br',
     packages=packages,