I'm facing an issue with my login component where it calls an http client service to send a request to the server for logging in. Everything works smoothly when I enter valid credentials, but if I input wrong credentials, the service doesn't seem to return any response at all.
Below is the method triggered upon clicking the login button:
submit(){
this.auth.tryLogin(this.form.getRawValue())
.subscribe(res => {
console.log(res);
if(res.status == 200){
this.router.navigate(['/'])
}
else{
alert(res.status)
}
})
}
And here's the code snippet for the service:
tryLogin(data : any) : Observable<HttpResponse<any>> {
return this.http.post<any>(environment.server + environment.routes.authRoutes.login, data, {
withCredentials: true,
observe: 'response'
})
}
When I enter the correct credentials, everything works as expected - the response is logged and I'm redirected to the homepage: https://i.stack.imgur.com/YOtFq.png
However, when I enter incorrect credentials, the status code isn't displayed in the alert message and I can't figure out why: https://i.stack.imgur.com/ZNjsX.png
Could it be that I'm using the http client incorrectly? Does it throw an exception when it receives an error code in the response? Is there something crucial that I might have overlooked?