My component has the following code snippet:
this.loginService.login(this.user, () => {
this.router.navigateByUrl('/');
});
Additionally, my service contains 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');
});
}
Is there a way for me to handle the error thrown by the login method when it is called from the component?