I'm trying to do the following with observables and I can't figure out what the best way would be to do it:
I'm calling a login endpoint using http. This service will return a token. I want to perform 2 different actions from 2 different points within the APP sequentially: when http resolves I need to store the provided token and then show a message. I tried the following:
return this.http.get(this.config.getApi('login'), params)
.map(response => response.json())
.do((data) => {
// Store token here
// If it fails, throw error
// Tried Observable.throw here but the subscriber doesn't get it.
}).subscribe(
(data) => {
// Everything went fine
},
() => {
// Either the http request failed or
// the process of storing the token threw an error.
}
);
Unfortunately, the subscribers to the returned observable never get error unless the http call fails. What operator should I use instead of do?
Thanks.