title: RxJava make retryWhen() fire to onError() method
body: <p>I have a following class with RxJava implementation for download two resources from API. I do some rx to allow it retry or repeat when it don't meet api/connection requirements. However, I cannot make retryWhen() fire onError() after attempt more than 3 times.</p>
  
  <p><strong>QUESTION / HELP</strong></p>
  
  <p>please, review my code and help me solve this issue.</p>
  
  <p><strong>NOTE</strong></p>
  
  <p>I'm implement Rx by read these two articles.
  <a href="https://medium.com/@v.danylo/server-polling-and-retrying-failed-operations-with-retrofit-and-rxjava-8bcc7e641a5a#.5itt4nvkl" rel="nofollow">article 1</a>, <a href="http://blog.danlew.net/2016/01/25/rxjavas-repeatwhen-and-retrywhen-explained/" rel="nofollow">article 2</a> </p>
  
  <p><strong>SplashPresenter.class</strong></p>
  
  <pre><code>public class SplashPresenter implements SplashContract.Presenter {
  
      private static final String TAG = SplashPresenter.class.getName();
      private static final int RETRY_TIMEOUT = 10;
      private static final int STOP_RETRY_TIME = 3;
      private static final int START_RETRY_TIME = 1;
  
  
      private SplashContract.View mView;
  
      @Override
      public void init(SplashContract.View view) {
          this.mView = view;
      }
  
      @Override
      public void onResume() {
  
          GetRemoteReceiverRelationshipSpec relationSpec = new GetRemoteReceiverRelationshipSpec();
          GetRemoteIncompleteReasonSpec reasonSpec = new GetRemoteIncompleteReasonSpec();
  
          Observable&lt;RepoResult&lt;ArrayList&lt;IncompleteReasonViewModel&gt;&gt;&gt; queryReason =
                  Repository.getInstance().query(reasonSpec);
  
          Repository.getInstance().query(relationSpec)
                  .concatMap(result -&gt; queryReason)
                  .repeatWhen(complete -&gt; complete
                          .zipWith(Observable.range(START_RETRY_TIME, STOP_RETRY_TIME), (v, i) -&gt; i)
                          .flatMap(repeatCount -&gt; {
                              Log.i(TAG, "Repeat attempt: " + repeatCount);
                              mView.showLoadingDialog();
                              return Observable.timer(RETRY_TIMEOUT,
                                      TimeUnit.SECONDS);
                          }))
                  .takeUntil(RepoResult::isSuccess)
                  .retryWhen(error -&gt; error
                          .zipWith(Observable.range(START_RETRY_TIME, STOP_RETRY_TIME), (v, i) -&gt; i)
                          .flatMap(retryCount -&gt; {
                              Log.i(TAG, "Retry attempt: " + retryCount);
                              mView.showLoadingDialog();
                              if (mView.getCommunicator() != null) {
                                  mView.getCommunicator().onConnectionFail(retryCount);
                              }
                              return Observable.timer(RETRY_TIMEOUT,
                                      TimeUnit.SECONDS);
                          }))
                  .filter(RepoResult::isSuccess)
                  .observeOn(AndroidSchedulers.mainThread())
                  .subscribe(
                          result -&gt; Log.i(TAG, "onNext()"),
                          err -&gt; {
                              Log.i(TAG, "onError()");
                              if (mView.getCommunicator() != null) {
                                  mView.dismissLoadingDialog();
                                  mView.getCommunicator().onSplashScreeDismissError();
                              }
                          },
                          () -&gt; {
                              Log.i(TAG, "onComplete()");
                              if (mView.getCommunicator() != null) {
                                  mView.dismissLoadingDialog();
                                  mView.getCommunicator().onSplashScreenSuccessDismiss();
                              }
                          }
                  );
      }
  
      @Override
      public void onPause() {
  
      }
  }
  </code></pre>