Reputation: 934
I have some basic flow I would like to implement using angular 2 and rxjs this is the flow:
Asumming the user is loged in, for each request:
if fails throw the error.
class MyHttpWrapper {
ctor(private http:Http) {}
get (url, options) {
//Do some pre request things with the options and url
return this.get(url,options)
.map(res => res.json())
.catch((err, source) => {
// Here i want to reloging
someService.login().subscribe(res =>
//Here i want to re-execute the original request and return it to the caller of the myHttpwrapper.get() caller
).catch(err =>
//return error to the caller of the myHttpWrapper.get()
)
}
}
How can I do that?
Upvotes: 2
Views: 1271
Reputation: 202176
I would try something like that:
return this.http.get(url,options)
.catch((err, source) => {
return someService.login()
.flatMap((res) => {
return this.http.get(url,options);
});
})
.map(res => res.json());
If there is an error on both login
and the second get
, the error will be thrown to the second callback of the subscribe
method.
Upvotes: 4