# HG changeset patch # User Goffi # Date 1371723406 -7200 # Node ID 5fdea93b25418ef17b8d843e8de1d68299a28411 # Parent 2bc6cf004e61749bc2e99068f578c79eba965850 browser side: errback management in bridge calls diff -r 2bc6cf004e61 -r 5fdea93b2541 libervia.py --- a/libervia.py Thu Jun 20 12:16:46 2013 +0200 +++ b/libervia.py Thu Jun 20 12:16:46 2013 +0200 @@ -41,39 +41,55 @@ JSONProxy.__init__(self, *args, **kwargs) self.handler=self self.cb={} + self.eb={} def call(self, method, cb, *args): - id = self.callMethod(method,args) + _id = self.callMethod(method,args) if cb: - self.cb[id] = cb + if isinstance(cb, tuple): + if len(cb) != 2: + print ("ERROR: tuple syntax for bridge.call is (callback, errback), aborting") + return + self.cb[_id] = cb[0] + self.eb[_id] = cb[1] + else: + self.cb[_id] = cb def onRemoteResponse(self, response, request_info): - if self.cb.has_key(request_info.id): + if request_info.id in self.cb: _cb = self.cb[request_info.id] - if isinstance(_cb, tuple): - #we have arguments attached to the callback - #we send them after the answer - callback, args = _cb - callback(response, *args) - else: - #No additional argument, we call directly the callback - _cb(response) + # if isinstance(_cb, tuple): + # #we have arguments attached to the callback + # #we send them after the answer + # callback, args = _cb + # callback(response, *args) + # else: + # #No additional argument, we call directly the callback + _cb(response) del self.cb[request_info.id] + if request_info.id in self.eb: + del self.eb[request_info.id] def onRemoteError(self, code, errobj, request_info): """def dump(obj): print "\n\nDUMPING %s\n\n" % obj for i in dir(obj): print "%s: %s" % (i, getattr(obj,i))""" - if code != 0: - print ("Internal server error") - """for o in code, error, request_info: - dump(o)""" + if request_info.id in self.eb: + _eb = self.eb[request_info.id] + _eb((code, errobj)) + del self.cb[request_info.id] + del self.eb[request_info.id] else: - if isinstance(errobj['message'],dict): - print("Error %s: %s" % (errobj['message']['faultCode'], errobj['message']['faultString'])) + if code != 0: + print ("Internal server error") + """for o in code, error, request_info: + dump(o)""" else: - print("Error: %s" % errobj['message']) + if isinstance(errobj['message'],dict): + print("Error %s: %s" % (errobj['message']['faultCode'], errobj['message']['faultString'])) + else: + print("Error: %s" % errobj['message']) class RegisterCall(LiberviaJsonProxy): def __init__(self):