From 8b6291644849e4c43d3ef9d53cf7037f0dcb7938 Mon Sep 17 00:00:00 2001 From: Aleksandar Ilic Date: Tue, 20 Feb 2024 20:11:54 +0100 Subject: [PATCH] Improve exceptions creation in PrimalApiClient --- .../primal/android/networking/primal/PrimalApiClient.kt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/src/main/kotlin/net/primal/android/networking/primal/PrimalApiClient.kt b/app/src/main/kotlin/net/primal/android/networking/primal/PrimalApiClient.kt index abe6f313..e59138f2 100644 --- a/app/src/main/kotlin/net/primal/android/networking/primal/PrimalApiClient.kt +++ b/app/src/main/kotlin/net/primal/android/networking/primal/PrimalApiClient.kt @@ -117,7 +117,11 @@ class PrimalApiClient @Inject constructor( } private fun Throwable?.takeAsWssException(): WssException { - return if (this is WssException) this else WssException(message = this?.message, cause = this) + return when (this) { + is WssException -> this + is NostrNoticeException -> WssException(message = this.reason, cause = this) + else -> WssException(message = this?.message, cause = this) + } } private suspend fun retry(times: Int, block: suspend () -> T): T { @@ -181,7 +185,7 @@ class PrimalApiClient @Inject constructor( val terminationMessage = messages.last() if (terminationMessage is NostrIncomingMessage.NoticeMessage) { - throw NostrNoticeException(reason = terminationMessage.message) + throw NostrNoticeException(reason = "${terminationMessage.message} [$subscriptionId]") } val events = messages.filterIsInstance(NostrIncomingMessage.EventMessage::class.java)