I am struggling to show specific error responses from the back-end in Sweetalert2 messages. I have been able to display general error text, but cannot figure out how to showcase the exact error message received from the API.
For instance, when entering an incorrect username, the API response is "{"message":"User Not Found"}"
Similarly, for an incorrect password, the API response is "{"message":"Authentication Failed"}"
In the code below, I tried changing the SweetAlert title to 'title: error.statusText,' but it only shows 'Bad request'.
How can I accurately display the specific error messages retrieved from the backend instead of just the error status text?
Furthermore, I am unsure why my console.log(error) is not functioning within the following code snippet.
signIn() {
this.authService.login(this.Username, this.Password).subscribe(
(data) => localStorage.setItem('Token', data),
(error) => Swal({
title: error.statusText,
type: 'warning',
confirmButtonText: 'Try Again'
}),
//console.log(error)
function (complete) {
Swal({
toast: true,
position: 'bottom',
type: 'success',
title: 'Login Successful!',
showConfirmButton: false,
timer: 3200
})
this.router.navigate(['/userDashboard']);
this.authService.setLoggedIn(true)
}.bind(this));
}