title: In Angular2, how to intercept error response from observable and pass it to the error channel
body: <p>I have a service which interacts with an api server. It has myHttpPost(data) method. This method should:</p>
  
  <ol>
  <li>call Angular's http.post to the server</li>
  <li>if response has status 200, provide the response's json content to subscriber</li>
  <li>if response has different status, process the response and provide processed error to the subscriber</li>
  </ol>
  
  <p>The current version of my method is:</p>
  
  <pre><code>postData(path: string, data: Object): Rx.Observable&lt;any&gt; {
      let json = JSON.stringify(data);
      return this.http.post(path, json)
          .map(res =&gt; res.json())
  }
  </code></pre>
  
  <p>This is not doing point 3 from the above list, because map is only called upon success and not on error. I could change the sequence by adding:</p>
  
  <pre><code>.catch(error =&gt; {
      let myError = prepareErrorContent(error);
      return Rx.Observable.throw(myError);
  });
  </code></pre>
  
  <p>Then the subscriber (another service) receives myError (that's ok) but the rxjs documentation says the following about catch() method: <em>"Continues an observable sequence that is terminated by an exception with the next observable sequence."</em> But I want the sequence to terminate normally and not to continue. If I use the <code>catch()</code> like above, then the next call to postData() from the subscriber does not work (it immediately returns the same error instead of making the http call). I think it's because the sequence is not terminated.</p>
  
  <p>How to do it?</p>
  
  <p>[Edit]
  This is my subscriber method which uses this service:</p>
  
  <pre><code> this.jsonHttp.postData(path, data)
      .subscribe(
          struct =&gt; onNext(struct),
          error =&gt; {
              let message = this.jsonHttp.extractError(error);
              onError(message)
          },
          () =&gt; onComplete ? onComplete() : null
      );
  </code></pre>