Public » FogBugz Middleware
Clone URL:  
Pushed to one repository · View In Graph Contained in 1.0, 1.1, and 1.2

initial commit

Changeset 39431ad95ec9

by Profile picture of Benjamin PollackBenjamin Pollack

Changes to one file · Browse files at 39431ad95ec9 Diff from another changeset...

Change 1 of 1 Show Entire File fogbugz.py Stacked
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
@@ -0,0 +1,35 @@
+import sys +import urllib, urllib2 +from django.conf import settings + +class FogBugzMiddleware(object): + """Report Django exceptions to FogBugz + + FogBugzMiddleware intercepts exceptions thrown from within Django + and forwards them to FogBugz' ScoutSubmit form. It will then + allow processing to continue--meaning that if you have Django + set to send an email on error, it will continue to do so.""" + + def process_exception(self, request, exception): + bug = {} + bug["ScoutUserName"] = settings.FOGBUGZ_USERNAME + bug["ScoutProject"] = settings.FOGBUGZ_PROJECT + bug["ScoutArea"] = settings.FOGBUGZ_AREA + bug["Description"] = 'Error (%s IP): %s' % ((request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS and 'internal' or 'EXTERNAL'), request.path) + + try: + request_repr = repr(request) + except: + request_repr = 'Request repr() unavailable' + bug["Extra"] = '%s\n\n%s' % (self._get_traceback(sys.exc_info()), request_repr) + + try: + urllib2.urlopen(settings.FOGBUGZ_URL, urllib.urlencode(bug)) + except: + # Don't throw an exception within the error handler! Bad! + pass + + def _get_traceback(self, exc_info): + """Helper function to return the traceback as a string""" + import traceback + return '\n'.join(traceback.format_exception(*(exc_info or sys.exc_info())))