From 64ce1b11dad6c30834475276e0e03a659168f6e7 Mon Sep 17 00:00:00 2001 From: Justin Brooks Date: Fri, 20 Oct 2023 09:28:21 -0400 Subject: [PATCH] Use a more specific type for error callbacks --- library/src/main/kotlin/com/connectrpc/ResponseMessage.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/src/main/kotlin/com/connectrpc/ResponseMessage.kt b/library/src/main/kotlin/com/connectrpc/ResponseMessage.kt index 4eeb992d..c7544ded 100644 --- a/library/src/main/kotlin/com/connectrpc/ResponseMessage.kt +++ b/library/src/main/kotlin/com/connectrpc/ResponseMessage.kt @@ -89,7 +89,7 @@ fun ResponseMessage<*>.exceptionOrNull(): Throwable? { */ inline fun ResponseMessage.fold( onSuccess: (value: T) -> R, - onFailure: (exception: Throwable) -> R, + onFailure: (exception: ConnectException) -> R, ): R { return when (this) { is ResponseMessage.Success -> onSuccess(this.message) @@ -114,7 +114,7 @@ fun ResponseMessage.getOrDefault(defaultValue: T): T { * * Note, that this function rethrows any [Throwable] exception thrown by [onFailure] function. */ -inline fun ResponseMessage.getOrElse(onFailure: (exception: Throwable) -> R): R { +inline fun ResponseMessage.getOrElse(onFailure: (exception: ConnectException) -> R): R { return when (this) { is ResponseMessage.Success -> this.message is ResponseMessage.Failure -> onFailure(this.cause)