Python exceptions can now be handled via QML

callCoro/callBackendCoro can now take onSuccess(result) and
onError(type, args, errorObject) callbacks.
This commit is contained in:
miruka
2019-10-28 06:26:02 -04:00
parent fe4eff62c5
commit 5894481dc5
4 changed files with 35 additions and 12 deletions

View File

@@ -14,18 +14,20 @@ Python {
return call_sync("APP.backend." + name, args)
}
function callCoro(name, args=[], callback=null) {
function callCoro(name, args=[], onSuccess=null, onError=null) {
let uuid = Math.random() + "." + name
pendingCoroutines[uuid] = callback || function() {}
pendingCoroutines[uuid] = {onSuccess, onError}
call("APP.call_backend_coro", [name, uuid, args])
}
function callClientCoro(accountId, name, args=[], callback=null) {
function callClientCoro(
accountId, name, args=[], onSuccess=null, onError=null
) {
callCoro("wait_until_client_exists", [accountId], () => {
let uuid = Math.random() + "." + name
pendingCoroutines[uuid] = callback || function() {}
pendingCoroutines[uuid] = {onSuccess, onError}
call("APP.call_client_coro", [accountId, name, uuid, args])
})
}

View File

@@ -13,8 +13,20 @@ function onAlertRequested() {
}
function onCoroutineDone(uuid, result) {
py.pendingCoroutines[uuid](result)
function onCoroutineDone(uuid, result, error) {
let onSuccess = py.pendingCoroutines[uuid].onSuccess
let onError = py.pendingCoroutines[uuid].onError
if (error) {
let type = py.getattr(py.getattr(error, "__class__"), "__name__")
let args = py.getattr(error, "args")
onError ?
onError(type, args, error) :
console.error(uuid + ": " + type + ": " + args)
} else if (onSuccess) { onSuccess(result) }
delete pendingCoroutines[uuid]
}