changeset 1314:8998f01088ac

browser (bridge): handle case where `callback` or `errback` is None
author Goffi <goffi@goffi.org>
date Sat, 01 Aug 2020 16:47:24 +0200
parents 12aa95eeb409
children 991ff12241e0
files libervia/pages/_browser/bridge.py
diffstat 1 files changed, 9 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- 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()