Download Install Tutorial Docs FAQ Tools WikiLicense Team IRC Planet Involvement Shop Book

Changeset 787

Show
Ignore:
Timestamp:
11/04/05 19:14:44
Author:
lawouach
Message:

The filter was not dealing with error raised within the application correctly. Now it does as expected. See http://www.cherrypy.org/wiki/XmlRpcIntrospection for an example.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/cherrypy/lib/filter/xmlrpcfilter.py

    r785 r787  
    170170         
    171171        path = cherrypy.request.objectPath 
    172          
    173         while True: 
    174             try: 
    175                 page_handler, object_path, virtual_path = cherrypy.request.mapPathToObject(path) 
    176                  
    177                 # Remove "root" from object_path and join it to get objectPath 
    178                 cherrypy.request.objectPath = '/' + '/'.join(object_path[1:]) 
    179                 args = virtual_path + cherrypy.request.paramList 
    180                 body = page_handler(*args, **cherrypy.request.paramMap) 
    181                 cherrypy.response.body = body 
    182                 return 
    183             except cherrypy.InternalRedirect, x: 
    184                 # Try again with the new path 
    185                 path = x.path 
     172        page_handler, object_path, virtual_path = cherrypy.request.mapPathToObject(path) 
     173 
     174        # Remove "root" from object_path and join it to get objectPath 
     175        cherrypy.request.objectPath = '/' + '/'.join(object_path[1:]) 
     176        args = virtual_path + cherrypy.request.paramList 
     177        body = page_handler(*args, **cherrypy.request.paramMap) 
     178        cherrypy.response.body = body 
    186179     
    187180    def beforeFinalize(self): 
     
    208201            if not cherrypy.request.xmlRpcFilterOn: 
    209202                return 
    210             body = ''.join([chunk for chunk in cherrypy.response.body]) 
     203            import sys 
     204            # Since we got here because of an exception, let's get its error message if any 
     205            message = str(sys.exc_info()[1]) 
     206            cherrypy.response.headerMap['Content-Type'] = 'text/xml' 
     207            cherrypy.response.headerMap['Content-Length'] = len(cherrypy.response.body[0]) 
     208            body = ''.join([chunk for chunk in message]) 
    211209            cherrypy.response.body = [xmlrpclib.dumps(xmlrpclib.Fault(1, body))] 
    212210        except: 
    213211            pass 
     212         
     213    def afterErrorResponse(self): 
     214        # The XML-RPC spec (http://www.xmlrpc.com/spec) says: 
     215        # "Unless there's a lower-level error, always return 200 OK." 
     216        # However if arrived here we do have a status set to 500 then 
     217        # it means we got an error we didn't want to trap explicitely 
     218        # so let's assume it's part of the "lower-level error" defined above. 
     219        if cherrypy.response.status[:3] != '500': 
     220            cherrypy.response.status = '200 OK' 

Hosted by WebFaction

Log in as guest/cpguest to create tickets