Skip to content

Commit f20e65d

Browse files
Update stream-android-core/src/main/java/io/getstream/android/core/api/utils/Result.kt
Co-authored-by: Copilot <[email protected]>
1 parent d4e2a2b commit f20e65d

File tree

1 file changed

+9
-6
lines changed
  • stream-android-core/src/main/java/io/getstream/android/core/api/utils

1 file changed

+9
-6
lines changed

stream-android-core/src/main/java/io/getstream/android/core/api/utils/Result.kt

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,13 @@ public inline fun <T, R> Result<T>.flatMap(transform: (T) -> Result<R>): Result<
4949
@StreamInternalApi
5050
public suspend fun <T> Result<T>.onTokenError(
5151
function: suspend (exception: StreamEndpointException, code: Int) -> Result<T>
52-
): Result<T> = onFailure {
53-
if (it is StreamEndpointException && it.apiError?.code?.div(10) == 4) {
54-
function(it, it.apiError.code)
55-
} else {
56-
this
52+
): Result<T> = fold(
53+
onSuccess = { this },
54+
onFailure = { throwable ->
55+
if (throwable is StreamEndpointException && throwable.apiError?.code?.div(10) == 4) {
56+
function(throwable, throwable.apiError.code)
57+
} else {
58+
this
59+
}
5760
}
58-
}
61+
)

0 commit comments

Comments
 (0)