android – RxJava2 Flowable Pair and Flatmap issue-ThrowExceptions

Exception or error:

I am getting this issue Type mismatch: inferred type is (Pair<Throwable, Boolean>) -> Unit but ((Pair<Throwable, Boolean>) -> Publisher<out (???..???)>!)! was expected

Here is my code

return RetrofitService.api.getdata(
        authToken,
        offset,
        limit
    )
        .subscribeOn(Schedulers.io())
        .observeOn(AndroidSchedulers.mainThread())
        .retryWhen { t ->
            t.zipWith(Flowable.range(1, 3),
                object : BiFunction<Throwable, Int, Pair<Throwable, Boolean>> {
                    override fun apply(t1: Throwable, t2: Int): Pair<Throwable, Boolean> {
                        if (t2 < 3 && t1 is HttpException && t1.code==401) {
                            return Pair(t1 as HttpException, true)
                        }
                        return Pair(t1 as HttpException, false)
                    }
                }).flatMap { t ->
                if (t.second) {
                    // refresh access_token with refresh_token

                        Repository.login(loginModel)
                        .map {
                            SharedPreferenceHelper.setAccessToken(it.accessToken)
                            SharedPreferenceHelper.setRefreshToken(it.refreshToken)
                        }.subscribe({

                        }, {

                        })
                    return@flatMap
                } else {
                    Single.error<Any>(t.first)
                }
            }
        }

I am trying to call getData api and whenever there is error for “401 token expire” I am refreshing access_token and retry. What should I return so that flatmap receives correct data.
`

How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *