Skip to content

Commit

Permalink
Use a more specific type for error callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
jzbrooks committed Oct 20, 2023
1 parent 34cf5b1 commit 64ce1b1
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions library/src/main/kotlin/com/connectrpc/ResponseMessage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ fun ResponseMessage<*>.exceptionOrNull(): Throwable? {
*/
inline fun <R, T> ResponseMessage<T>.fold(
onSuccess: (value: T) -> R,
onFailure: (exception: Throwable) -> R,
onFailure: (exception: ConnectException) -> R,
): R {
return when (this) {
is ResponseMessage.Success -> onSuccess(this.message)
Expand All @@ -114,7 +114,7 @@ fun <T> ResponseMessage<T>.getOrDefault(defaultValue: T): T {
*
* Note, that this function rethrows any [Throwable] exception thrown by [onFailure] function.
*/
inline fun <R, T : R> ResponseMessage<T>.getOrElse(onFailure: (exception: Throwable) -> R): R {
inline fun <R, T : R> ResponseMessage<T>.getOrElse(onFailure: (exception: ConnectException) -> R): R {
return when (this) {
is ResponseMessage.Success -> this.message
is ResponseMessage.Failure -> onFailure(this.cause)
Expand Down

0 comments on commit 64ce1b1

Please sign in to comment.