I am making a server call as shown below:
In the case of success,
STATUS---200
{error_code: 0, status: "success", results: [,…], message: "Album successfully found."}
If there is a failure, STATUS---401
Login credentials are incorrect.
To handle this, I have implemented the following code:
Upon sending a POST request to this.serverUrl+'login' with loginForm.value and headers,
.subscribe(response => {
if (response.json().error_code === 0) {
console.log('success');
} else {
console.log('fail');
}
})
}
However, in the current scenario, an error (401-status) occurs. This prevents the execution from going into the else statement. Can someone provide assistance on how to properly handle or catch this error? Thank you.