I’m working on a dispatcher for RPC calls via a webserver. The webserver class has some methods like rpc_echo, rpc_add, … (prefixed with rpc_) which should be accessable from remote. In the dispatcher method I can find the corresponding method and call it with the prepared arguments in the dictionary :
try:
handler = getattr(self, 'rpc_' + request['method']) # identify handler
response['result'] = handler(**params) # assign arguments and call handler
except (AttributeError, KeyError):
# exceptions: requested method -> key, call method -> attr, callable -> attr
raise JSONRPCError('unknown method.')
except TypeError:
raise JSONRPCError('parameters don\'t match method prototype.')
This is working fine: But if there is thrown an exception inside the handler the error checking is disturbed and leads to wrong conclusions. How can I find out if the exception was thrown inside handler or not? Thus a wrong call or a server error?
you probably want to spend some time with traceback module
here is a simplified example:
Output: