[CalendarServer-changes] [9961] CalendarServer/branches/users/glyph/always-abort-txn-on-error

source_changes at macosforge.org source_changes at macosforge.org
Mon Oct 22 16:09:15 PDT 2012


Revision: 9961
          http://trac.calendarserver.org//changeset/9961
Author:   glyph at apple.com
Date:     2012-10-22 16:09:15 -0700 (Mon, 22 Oct 2012)
Log Message:
-----------
Give application code an opportunity to handle HTTPErrors close to the source.

Modified Paths:
--------------
    CalendarServer/branches/users/glyph/always-abort-txn-on-error/twext/web2/resource.py

Property Changed:
----------------
    CalendarServer/branches/users/glyph/always-abort-txn-on-error/

Modified: CalendarServer/branches/users/glyph/always-abort-txn-on-error/twext/web2/resource.py
===================================================================
--- CalendarServer/branches/users/glyph/always-abort-txn-on-error/twext/web2/resource.py	2012-10-22 23:09:14 UTC (rev 9960)
+++ CalendarServer/branches/users/glyph/always-abort-txn-on-error/twext/web2/resource.py	2012-10-22 23:09:15 UTC (rev 9961)
@@ -34,6 +34,7 @@
 
 from twext.web2 import iweb, http, server, responsecode
 
+from twisted.internet.defer import maybeDeferred
 class RenderMixin(object):
     """
     Mix-in class for L{iweb.IResource} which provides a dispatch mechanism for
@@ -106,9 +107,20 @@
             returnValue(response)
 
         yield self.checkPreconditions(request)
-        returnValue((yield method(request)))
+        result = maybeDeferred(method, request)
+        result.addErrback(self.methodRaisedException)
+        returnValue((yield result))
 
 
+    def methodRaisedException(self, failure):
+        """
+        An C{http_METHOD} method raised an exception; this is an errback for
+        that exception.  By default, simply propagate the error up; subclasses
+        may override this for top-level exception handling.
+        """
+        return failure
+
+
     def http_OPTIONS(self, request):
         """
         Respond to a OPTIONS request.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20121022/17773f3a/attachment.html>


More information about the calendarserver-changes mailing list