title: RxJS - Skip to subscribe
body: <p>I was wondering if there was a way to cause an observable to skip to the subscribe operator (without terminating). The use case for me is that, I have a 'loginClicked' observable (a subject) where I perform an API call and then subscribe to the next event. The API call is performed using promises and any error I encounter, I wrap in a</p>
  
  <pre><code>Promise.resolve(error)
  </code></pre>
  
  <p>so that the observable does not terminate (allowing them to try and login again using the same observable (subject)).</p>
  
  <p>However before I call the API I want to do use </p>
  
  <pre><code>doOnNext()
  </code></pre>
  
  <p>to check the internet connectivity. If there IS a connection then continue as normal. However, if there isn't anything, I want to immediately go straight to the onNext callback of subscribe passing in some 'NoConnectivityError'. </p>
  
  <p>Is there anything that will help me solve this or am I going about it the wrong way?</p>
  
  <p>Thanks.</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>For example:</p>
  
  <pre><code>this.loginClickedStream
      .doOnNext(function() {
          if (!connectedToWifi) {
              //Skip to subscribe passing some data somehow
              skipToSubscribe({error: 'NotConnectedToWifi'});
          } 
      })
      .flatMap(function() {
          return fetch(url);
      })
      .subscribe(function(response) {
          if (response.error === 'NotConnectedToWifi') {
           //Show alert
          } else if (response.ok) {
              //Display response in UI
          } else {
              //Show alert showing error
          }
      });
  </code></pre>
  
  <p>Notice how when the user is not connected to wifi the observable is passed directly to the subscribe method. I hope that is clearer.</p>