# HG changeset patch # User Goffi # Date 1596293244 -7200 # Node ID 8998f01088ac024eb05a2c9c8a9c088abf41924f # Parent 12aa95eeb409ca92b2d3d1b41913d397e38f5892 browser (bridge): handle case where `callback` or `errback` is None diff -r 12aa95eeb409 -r 8998f01088ac libervia/pages/_browser/bridge.py --- a/libervia/pages/_browser/bridge.py Sat Aug 01 16:47:24 2020 +0200 +++ b/libervia/pages/_browser/bridge.py Sat Aug 01 16:47:24 2020 +0200 @@ -10,17 +10,20 @@ def on_load(self, xhr, ev, callback, errback): if xhr.status == 200: ret = javascript.JSON.parse(xhr.response) - if ret is None: - callback() - else: - callback(ret) + if callback is not None: + if ret is None: + callback() + else: + callback(ret) elif xhr.status == 502: # PROXY_ERROR is used for bridge error ret = javascript.JSON.parse(xhr.response) - errback(ret) + if errback is not None: + errback(ret) else: print(f"bridge called failed: code: {xhr.response}, text: {xhr.statusText}") - errback({"fullname": "InternalError", "message": xhr.statusText}) + if errback is not None: + errback({"fullname": "InternalError", "message": xhr.statusText}) def call(self, method_name, *args, callback, errback, **kwargs): xhr = window.XMLHttpRequest.new()