Reputation: 11
I am checking the user's token logged, if the authentication fails (returns a 401 error) I want to redirect to the login. The problem I'm encountering is that when I make the error catch the router.navigate does not work.
constructor(private http: Http , private router : Router )
authUser(){
return this.http.get(this.baseEndPoint+'/auth/user',Helpers.requestAuthOptions())
.map((response) => response.json())
.catch(this.handleError.bind(this));
}
public handleError = (error) => {
this.router.navigate(['/login']);
console.log('Hello!');//Hello appears in my console
return Observable.throw(error);
};
Upvotes: 0
Views: 1093
Reputation: 2228
Just import RxJS catch Extension.
import 'rxjs/add/operator/catch';
How to catch exception correctly from http.request()?
Upvotes: 0