Anonymous avatar Anonymous committed 9b81bf0

Adding handling of uncaught exceptions from protocols.

Comments (0)

Files changed (1)

t5437/t5437-protocol_api-r7194.diff

 new file mode 100644
 --- /dev/null
 +++ b/trunk/tracrpc/json_rpc.py
-@@ -0,0 +1,207 @@
+@@ -0,0 +1,205 @@
 +# -*- coding: utf-8 -*-
 +"""
 +License: BSD
 +    def rpc_process(self, req, content_type):
 +        """ Handles JSON-RPC requests """
 +        if not json:
-+            self.log.debug("RPC(json) call ignored (not available).")
-+            self._send_response(req, "Error: JSON-RPC not available.\n",
-+                                content_type)
++            raise RPCError("RPC(json) error. JSON not available.")
 +        try:
 +            data = json.load(req, cls=TracRpcJSONDecoder)
 +        except Exception, e:
 diff --git a/trunk/tracrpc/web_ui.py b/trunk/tracrpc/web_ui.py
 --- a/trunk/tracrpc/web_ui.py
 +++ b/trunk/tracrpc/web_ui.py
-@@ -6,305 +6,133 @@
+@@ -6,305 +6,139 @@
  (c) 2009      ::: www.CodeResort.com - BV Network AS (simon-code@bvnetwork.no)
  """
  
 +        content_type = req.get_header('Content-Type') or 'text/html'
 +        if protocol:
 +            # Perform the method call
-+            protocol.rpc_process(req, content_type)
-+            raise RequestDone
++            try:
++                protocol.rpc_process(req, content_type)
++            except Exception, e:
++                # Unhandled protocol exception
++                self.log.error("Unhandled protocol error: %s" % to_unicode(e))
++                req.send_error(None, template='', content_type='text/plain',
++                        status=500, env=None, data=to_unicode(e))
 +        elif accepts_mimetype(req, 'text/html'):
 +            return self._dump_docs(req)
 +        else:
 +            # Attempt at API call gone wrong. Raise a plain-text 415 error
 +            body = "No protocol matching Content-Type '%s' at path '%s'." % (
 +                                                content_type, req.path_info)
++            self.log.error(body)
 +            req.send_error(None, template='', content_type='text/plain',
 +                    status=HTTPUnsupportedMediaType.code, env=None, data=body)
  
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.