Skip to content

Commit

Permalink
Improve exceptions creation in PrimalApiClient
Browse files Browse the repository at this point in the history
  • Loading branch information
AleksandarIlic committed Feb 20, 2024
1 parent b26096b commit 8b62916
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 <T> retry(times: Int, block: suspend () -> T): T {
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 8b62916

Please sign in to comment.