Unverified Commit d23599a5 authored by Isis Lovecruft's avatar Isis Lovecruft
Browse files

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
 * FIXES #6127
parent 7de5929d
......@@ -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)
response = self.getBridgeRequestAnswer(request)
except Exception as err:
response = self.renderAnswer(request)
return response
def getBridgeRequestAnswer(self, request):
"""Respond to a client HTTP request for bridges.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment