Subscribe twice to Angular 2 Http?
<p>I would like to have a service for calling an API that properly processes a request and performs standard error handling on the API requests.  For instance I have an <code>ApiErrorsService</code> that I want to call when any API call gets an error.  I also want to submit calls in a standard way, i.e. setting the Content-Type to application/json and serializing the request object.</p>

<p>Of course when I subscribe to the observable returned from <code>Http</code> it is called once, and when I return it and the caller subscribes it is called again.  What would be the best way to be able to listen for the results in two places without performing the API call twice?  Can I just call <code>.publish()</code> or <code>.share()</code> and return that?  Do I need to then dispose of it?  Are there any timing issues that may occur?  If I mock the API call and return a value immediately will that work fine, or will the caller's subscription miss the values?  Here's the code I have:</p>

<pre><code>post(path: string, data: any): Observable&lt;Response&gt; {
    var headers: Headers = new Headers();
    headers.set("Content-Type", "application/json");
    var s = data == null ? null : JSON.stringify(data, null, 2);
    var shared = this.http.post(path, s, { headers: headers }).share();
    shared.subscribe(null, err =&gt; this.appErrorsService.addApiError(err));
    return shared;
}
</code></pre>