[tor-commits] [bridgedb/master] Add exception-catching wrapper to bridgedb.HTTPServer.render().

isis at torproject.org isis at torproject.org
Sun Jan 12 06:06:36 UTC 2014


commit d23599a5b87f0e85a65b35575457d0c0f785eacb
Author: Isis Lovecruft <isis at torproject.org>
Date:   Sun Jan 12 01:37:51 2014 +0000

    Add exception-catching wrapper to bridgedb.HTTPServer.render().
    
     * ADD a wrapper which catches all unhandled exceptions which occur
       while generating an HTML response. If such an exception occurs, this
       ensures that the error is logged and the default "No bridges
       currently available" response is served to the client (rather than
       display a traceback to the client, which is what BridgeDB did
       previously).
     * FIXES #6127
---
 lib/bridgedb/HTTPServer.py |   20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/lib/bridgedb/HTTPServer.py b/lib/bridgedb/HTTPServer.py
index 856a753..fc637a4 100644
--- a/lib/bridgedb/HTTPServer.py
+++ b/lib/bridgedb/HTTPServer.py
@@ -150,9 +150,25 @@ class WebResource(twisted.web.resource.Resource):
     def render(self, request):
         """Render a response for a client HTTP request.
 
-        Presently, this method merely returns :meth:`getBridgeRequestAnswer`.
+        Presently, this method merely wraps :meth:`getBridgeRequestAnswer` to
+        catch any unhandled exceptions which occur (otherwise the server will
+        display the traceback to the client). If an unhandled exception *does*
+        occur, the client will be served the default "No bridges currently
+        available" HTML response page.
+
+        :type request: :api:`twisted.web.http.Request`
+        :param request: A ``Request`` object containing the HTTP method, full
+                        URI, and any URL/POST arguments and headers present.
+        :rtype: str
+        :returns: A plaintext or HTML response to serve.
         """
-        return self.getBridgeRequestAnswer(request)
+        try:
+            response = self.getBridgeRequestAnswer(request)
+        except Exception as err:
+            logging.exception(err)
+            response = self.renderAnswer(request)
+
+        return response
 
     def getBridgeRequestAnswer(self, request):
         """Respond to a client HTTP request for bridges.





More information about the tor-commits mailing list