I have a component with this:
this.loginService.login(this.user, () => {
this.router.navigateByUrl('/');
});
And a service with this method:
login(credentials, callback) {
const headers = new HttpHeaders(credentials ?
{ authorization: 'Basic ' + btoa(credentials.email + ':' + credentials.password) }
: {});
this.http.get(this.API.crudAdmin + 'admin?email=' + credentials.email,
{ headers: headers }).subscribe(response => {
if (response['name']) {
this.authenticated = true;
} else {
this.authenticated = false;
}
return callback && callback();
}, error => {
throw new Error('Error');
});
}
How could I catch the error thrown from login method when I call it from the component?