comparison libervia/server/server.py @ 1138:ef565839dada

server: don't convert failure in errback to jsonrpclib.Fault anymore: failure in bridgeCall was always converted to jsonrpclib.Fault, resulting in loss of useful debugging data. This conversion as been modified to the signal handler which is only used by Libervia Legacy. Note that txJsonRPC will be totally removed for 0.8 release.
author Goffi <goffi@goffi.org>
date Fri, 11 Jan 2019 16:38:25 +0100
parents 0cafb79ced6d
children 2af117bfe6cc
comparison
equal deleted inserted replaced
1137:dfd6545a205a 1138:ef565839dada
525 class JSONRPCMethodManager(jsonrpc.JSONRPC): 525 class JSONRPCMethodManager(jsonrpc.JSONRPC):
526 def __init__(self, sat_host): 526 def __init__(self, sat_host):
527 jsonrpc.JSONRPC.__init__(self) 527 jsonrpc.JSONRPC.__init__(self)
528 self.sat_host = sat_host 528 self.sat_host = sat_host
529 529
530 def _bridgeCallEb(self, failure_):
531 """Raise a jsonrpclib failure for the frontend"""
532 return failure.Failure(
533 jsonrpclib.Fault(C.ERRNUM_BRIDGE_ERRBACK, failure_.value.classname)
534 )
535
530 def asyncBridgeCall(self, method_name, *args, **kwargs): 536 def asyncBridgeCall(self, method_name, *args, **kwargs):
531 return self.sat_host.bridgeCall(method_name, *args, **kwargs) 537 d = self.sat_host.bridgeCall(method_name, *args, **kwargs)
538 d.addErrback(self._bridgeCallEb)
539 return d
532 540
533 541
534 class MethodHandler(JSONRPCMethodManager): 542 class MethodHandler(JSONRPCMethodManager):
535 def __init__(self, sat_host): 543 def __init__(self, sat_host):
536 JSONRPCMethodManager.__init__(self, sat_host) 544 JSONRPCMethodManager.__init__(self, sat_host)
1572 """ 1580 """
1573 _session = request.getSession() 1581 _session = request.getSession()
1574 parsed = jsonrpclib.loads(request.content.read()) 1582 parsed = jsonrpclib.loads(request.content.read())
1575 profile = session_iface.ISATSession(_session).profile 1583 profile = session_iface.ISATSession(_session).profile
1576 if not profile: 1584 if not profile:
1585 # FIXME: this method should not use _cbRender
1586 # but all txJsonRPC code will be removed in 0.8 in favor of webRTC
1587 # and it is currently used only with Libervia legacy app,
1588 # so we do a is_jsonp workaround for now
1589 self.is_jsonp = False
1577 # user is not identified, we return a jsonrpc fault 1590 # user is not identified, we return a jsonrpc fault
1578 fault = jsonrpclib.Fault( 1591 fault = jsonrpclib.Fault(
1579 C.ERRNUM_LIBERVIA, C.NOT_ALLOWED 1592 C.ERRNUM_LIBERVIA, C.NOT_ALLOWED
1580 ) # FIXME: define some standard error codes for libervia 1593 ) # FIXME: define some standard error codes for libervia
1581 return jsonrpc.JSONRPC._cbRender( 1594 return jsonrpc.JSONRPC._cbRender(
1582 self, fault, request, parsed.get("id"), parsed.get("jsonrpc") 1595 self, fault, request, parsed.get("id"), parsed.get("jsonrpc")
1583 ) # pylint: disable=E1103 1596 )
1584 self.request = request 1597 self.request = request
1585 return jsonrpc.JSONRPC.render(self, request) 1598 return jsonrpc.JSONRPC.render(self, request)
1586 1599
1587 1600
1588 class UploadManager(web_resource.Resource): 1601 class UploadManager(web_resource.Resource):
2024 else: 2037 else:
2025 if len(args) != 1: 2038 if len(args) != 1:
2026 Exception("Multiple return arguments not supported") 2039 Exception("Multiple return arguments not supported")
2027 d.callback(args[0]) 2040 d.callback(args[0])
2028 2041
2029 def _errback(result): 2042 def _errback(failure_):
2030 d.errback( 2043 d.errback(failure.Failure(failure_))
2031 failure.Failure(
2032 jsonrpclib.Fault(C.ERRNUM_BRIDGE_ERRBACK, result.classname)
2033 )
2034 )
2035 2044
2036 kwargs["callback"] = _callback 2045 kwargs["callback"] = _callback
2037 kwargs["errback"] = _errback 2046 kwargs["errback"] = _errback
2038 getattr(self.bridge, method_name)(*args, **kwargs) 2047 getattr(self.bridge, method_name)(*args, **kwargs)
2039 return d 2048 return d
2196 2205
2197 self.waiting_profiles.setRequest(request, profile, register_with_ext_jid) 2206 self.waiting_profiles.setRequest(request, profile, register_with_ext_jid)
2198 try: 2207 try:
2199 connected = yield self.bridgeCall(connect_method, profile, password) 2208 connected = yield self.bridgeCall(connect_method, profile, password)
2200 except Exception as failure_: 2209 except Exception as failure_:
2201 fault = failure_.faultString 2210 fault = failure_.classname
2202 self.waiting_profiles.purgeRequest(profile) 2211 self.waiting_profiles.purgeRequest(profile)
2203 if fault in ("PasswordError", "ProfileUnknownError"): 2212 if fault in ("PasswordError", "ProfileUnknownError"):
2204 log.info(u"Profile {profile} doesn't exist or the submitted password is " 2213 log.info(u"Profile {profile} doesn't exist or the submitted password is "
2205 u"wrong".format( profile=profile)) 2214 u"wrong".format( profile=profile))
2206 raise failure.Failure(ValueError(C.PROFILE_AUTH_ERROR)) 2215 raise failure.Failure(ValueError(C.PROFILE_AUTH_ERROR))
2211 elif fault == "NoReply": 2220 elif fault == "NoReply":
2212 log.info(_(u"Did not receive a reply (the timeout expired or the " 2221 log.info(_(u"Did not receive a reply (the timeout expired or the "
2213 u"connection is broken)")) 2222 u"connection is broken)"))
2214 raise exceptions.TimeOutError 2223 raise exceptions.TimeOutError
2215 else: 2224 else:
2216 log.error(u'Unmanaged fault string "{fault}" in errback for the ' 2225 log.error(u'Unmanaged fault class "{fault}" in errback for the '
2217 u'connection of profile {profile}'.format( 2226 u'connection of profile {profile}'.format(
2218 fault=fault, profile=profile)) 2227 fault=fault, profile=profile))
2219 raise failure.Failure(exceptions.InternalError(fault)) 2228 raise failure.Failure(exceptions.InternalError(fault))
2220 2229
2221 if connected: 2230 if connected: