首页 > 解决方案 > Kotlin Flow 的手动重试

问题描述

如果您已将错误处理委托给扩展函数,是否有办法在 Kotlin 中手动重试失败的流程。

我发布了一个类似的问题:Kotlin Flow, callback

如果我的流程的errorHandle 是下面的那个。

fun <T> Flow<T>.handleErrors(showError: Boolean = false, retry: Boolean = false, 
                             navigateBack: Boolean = true): Flow<T> =
    catch { throwable ->

        var message: String? = null

        if (showError) {
            when (throwable) {

                is HttpException -> {
                  postEvent(EventType(retry))
                }
             }
          }

如何使用流手动重试失败的 api 调用。

标签: androidkotlin-coroutineskotlin-android-extensionskotlin-flow

解决方案


推荐阅读