I would like to know how errors should be handled having webservices
running with XMLRPCController.
Say I have a "def login(self, user, password)" method. If the login
fails, how should I return the errors to the client? I saw, from the
following docs:
http://wiki.pylonshq.com/display/pylonsdocs/Using+the+XMLRPCController
that a convenient fault handler function is provided:
def xmlrpc_fault(code, message):
"""Convenience method to return a Pylons response XMLRPC Fault"""
So I imported this function in my controller:
from pylons.controllers.xmlrpc import xmlrpc_fault
and added to my login method:
user = model.User.query.filter_by(user=user, password=password).one()
if not user:
return xmlrpc_fault(LOGIN_ERR, "incorrect login")
Is this how it should be handled ? If it is, I have the following error
message:
exceptions.TypeError: cannot marshal <class
'paste.wsgiwrappers.WSGIResponse'> objects
Regards,
--
Alexandre CONRAD
I've done something like this in my controller:
def __call__(self, environ, start_response):
# Wrap an exception in an XMLRPC fault
try:
return XMLRPCController.__call__(self, environ, start_response)
except:
logException()
if asbool(config['global_conf']['debug']):
return xmlrpc_fault(0,
traceback.format_exc())(environ, start_response)
else:
return xmlrpc_fault(0, "An internal server error
occurred")(environ, start_response)
finally:
Session.remove()
Note the call to the return value of xmlrpc_fault with (environ, start_response)
HTH,
Chris
thank you for the response. I'll have a try with your code and see how
it runs with me.
Regards,
Chris AtLee wrote:
--
Alexandre CONRAD - TLV FRANCE
Research & Development