0

I`m trying to implement a autoLogin function with retry when and need to change the parameters of the previous observable after the auto login is done.

So i created a function

class TestClass(): Function<Flowable<out Throwable>, Flowable<*>> {
    override fun apply(flowable: Flowable<out Throwable>): Flowable<*> {
        return flowable
                .flatMap {
                    if (it is HttpException && it.code() == 401 ) {
                        Timber.d("apply: Doing AutoLogin.")
                        dataSource
                                .login(document, password)
                                .map {
                                    //Auto login done, update user
                                }
                                .doOnError({ 
                                    // login failed
                                })
                                .toFlowable()
                    } else {
                        Flowable.error(it)
                    }
                }
    }
}

And apply it this way:

dataSource.apiCall(user)            
            .retryWhen(TestClass())
            .subscribe()

Tried this way too:

    Single.defer { 
                dataSource.apiCall(user)            
                    .retryWhen(TestClass())
            }
            .subscribe()

}

The problem is, after the login when the request is retried, the user isn`t updated.

What i`m doing wrong?

0 Answers0