title: Get remote data or get local via rxJava 2
body: <p>I has very simple task to send request for remote data. But need to handle my request and get local on remote error. 
  Functionality way like a mathematics has many ways to solve problem.</p>
  
  <p>So first ost simple сomes to mind to do this:</p>
  
  <pre><code>val remote = remotePurchase
                  .getAvailableUsersMaxCount()
                  .subscribe({},{
                     //on failed            
                    getLocal()
          })
  </code></pre>
  
  <p>But i thing it is rx beginner guy also it is callback in callback bad way.</p>
  
  <p>Also i think to do this:</p>
  
  <pre><code>  override fun getActualUsersMaxCount(): Observable&lt;Int&gt; {
              return remotePurchase
                      .getAvailableUsersMaxCount()
  
                      .flatMap {
                          updateUsersCount(it)
                      }
                      .onErrorReturn {
                          userLocal.getById(PrefProvider.userId).map {
                              it.chatUsersCount?:0
                          }.blockingFirst()
                      }
          }
  </code></pre>
  
  <p>Bute some times handle: </p>
  
  <blockquote>
    <p>Caused by: rx.exceptions.CompositeException: 2 exceptions occurred. </p>
  </blockquote>
  
  <p>Like this github.com/ReactiveX/RxJava/issues/3679 </p>
  
  <p>Then i known about using toBlocking is not best idea. See <a href="https://stackoverflow.com/q/50023866/6352712">post here</a>.</p>
  
  <p>After some time i decided mutch better this: </p>
  
  <pre><code> override fun getActualUsersMaxCount(): Observable&lt;Int&gt; {
  
      val remote = remotePurchase
              .getAvailableUsersMaxCount()
              .flatMap {
                  updateUsersCount(it)
              }.onErrorReturn { -1 }
  
      return zip(remote, userLocal.getById(PrefProvider.userId).map {
          it.chatUsersCount ?: 0
      }, { remoteCount, localCount -&gt;
  
          if(remoteCount!= -1) remoteCount else localCount
  
      })
  }
  </code></pre>
  
  <p>So now i almost control situation. If i got error from network I can check it and receive local result</p>
  
  <p>But what variation better as you think? May be there is more simplify decision?</p>