I return in my front-end(Angular10) a back-end(ASP.NET) message using angular alertService, but only show statusText equals NotFound, when should be "Usuário não encontrado.", in network a message is appears, but in alert not.
login.component.ts
onSubmit() {
this.submitted = true;
// reset alerts on submit
this.alertService.clear();
// stop here if form is invalid
if (this.form.invalid) {
return;
}
error: HttpErrorResponse ;
this.loading = true;
this.accountService.login(this.f.user_nome.value, this.f.user_accessKey.value)
.pipe(first())
.subscribe({
next: () => {
// get return url from query parameters or default to home page
const returnUrl = this.route.snapshot.queryParams['returnUrl'] || '/';
this.router.navigateByUrl(returnUrl);
},
error: error => {
this.alertService.error(error);
this.loading = false;
}
});
}
account.service.ts
login(user_nome, user_accessKey) {
return this.http.post<User>(`${environment.apiUrl}/Conta/v1/login`, { user_nome,user_accessKey })
.pipe(map(user => {
// store user details and jwt token in local storage to keep user logged in between page refreshes
localStorage.setItem('user', JSON.stringify(user));
this.userSubject.next(user);
return user;
}));
}