diff --git a/gradle.properties b/gradle.properties index 78c3e46..513ac46 100644 --- a/gradle.properties +++ b/gradle.properties @@ -19,7 +19,7 @@ RELEASE_SIGNING_ENABLED=true GROUP=eu.lepicekmichal.signalrkore POM_ARTIFACT_ID=signalrkore -VERSION_NAME=0.7.1 +VERSION_NAME=0.8.0 POM_NAME=SignalR Kore POM_DESCRIPTION=Connect to SignalR Core server with library written in Kotlin and coroutines. diff --git a/signalrkore/src/commonMain/kotlin/eu/lepicekmichal/signalrkore/HubCommunicationLink.kt b/signalrkore/src/commonMain/kotlin/eu/lepicekmichal/signalrkore/HubCommunicationLink.kt index bf1d429..6de2d76 100644 --- a/signalrkore/src/commonMain/kotlin/eu/lepicekmichal/signalrkore/HubCommunicationLink.kt +++ b/signalrkore/src/commonMain/kotlin/eu/lepicekmichal/signalrkore/HubCommunicationLink.kt @@ -196,7 +196,15 @@ abstract class HubCommunicationLink(private val json: Json) : HubCommunication() collectInScope(scope) { message -> when (message) { is HubMessage.Invocation.NonBlocking -> { - callback(message) + try { + callback(message) + } catch (ex: Exception) { + logger.log( + severity = Logger.Severity.ERROR, + message = "Getting result for non-blocking invocation of '${message.target}' method has thrown an exception", + cause = ex, + ) + } if (resultType != Unit::class) { // todo should I also print the actual result inside message? logger.log( @@ -240,32 +248,33 @@ abstract class HubCommunicationLink(private val json: Json) : HubCommunication() if (hasResult && resultProviderRegistry.contains(target)) { throw IllegalStateException("There can be only one function for returning result on blocking invocation (method: $target)") } - return receivedInvocations .run { - if (!hasResult) { - this.onEach { - if (it is HubMessage.Invocation.Blocking) { - logger.log( - severity = Logger.Severity.WARNING, - message = "There is no result provider for ${it.target} despite server expecting it.", - cause = null, - ) - complete( - HubMessage.Completion.Error( - invocationId = it.invocationId, - error = "Client did not provide a result." - ), - ) - } + if (!hasResult) this + else this + .onSubscription { resultProviderRegistry.add(target) } + .onCompletion { resultProviderRegistry.remove(target) } + } + .filter { it.target == target } + .run { + if (hasResult) this + else this.onEach { + if (it is HubMessage.Invocation.Blocking) { + logger.log( + severity = Logger.Severity.WARNING, + message = "There is no result provider for ${it.target} despite server expecting it.", + cause = null, + ) + + complete( + HubMessage.Completion.Error( + invocationId = it.invocationId, + error = "Client did not provide a result." + ), + ) } - } else { - this - .onSubscription { resultProviderRegistry.add(target) } - .onCompletion { resultProviderRegistry.remove(target) } } } - .filter { it.target == target } .onEach { logger.log(Logger.Severity.INFO, "Received invocation: $it", null) } } } \ No newline at end of file