From 5763aa3b0004b678d7791b32e1a92b6facb9b17e Mon Sep 17 00:00:00 2001 From: Robert Jaros Date: Fri, 1 Nov 2019 17:44:31 +0100 Subject: Better exception handling in server-side interfaces. --- .../src/main/kotlin/pl/treksoft/kvision/remote/CallAgent.kt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'kvision-modules/kvision-remote/src/main/kotlin') diff --git a/kvision-modules/kvision-remote/src/main/kotlin/pl/treksoft/kvision/remote/CallAgent.kt b/kvision-modules/kvision-remote/src/main/kotlin/pl/treksoft/kvision/remote/CallAgent.kt index 64c257cd..0a56465d 100644 --- a/kvision-modules/kvision-remote/src/main/kotlin/pl/treksoft/kvision/remote/CallAgent.kt +++ b/kvision-modules/kvision-remote/src/main/kotlin/pl/treksoft/kvision/remote/CallAgent.kt @@ -71,7 +71,13 @@ open class CallAgent { { data: dynamic, _: Any, _: Any -> when { data.id != jsonRpcRequest.id -> reject(Exception("Invalid response ID")) - data.error != null -> reject(Exception(data.error.toString())) + data.error != null -> { + if (data.exceptionType == "pl.treksoft.kvision.remote.ServiceException") { + reject(ServiceException(data.error.toString())) + } else { + reject(Exception(data.error.toString())) + } + } data.result != null -> resolve(data.result) else -> reject(Exception("Invalid response")) } -- cgit