Auth Service
logout() {
return this.http.post(this.logOutApi, null);
}
The status code doesn\'t show in the json response from t
Other than 200 you get the status code in your error block. So here you will have to handle accordingly like below
logout() {
this.chk.logout().subscribe((res: any)=>{
if(res.status == 200) //doesnt work{
console.log(res);
})
}
}, (error)=>{
if (error.status === 500) {
alert('Server down please try after some time');
}
else if (error.status === 404) {
alert('Server down. Please try after some time');
}
});
}
Hope this help
It comes under error
callback
, (err)=>{
alert(err.status);
});
You can use the option of { observe: 'response' }
to read the full response including the status code in the success handler. This would give you access to a response of type HttpResponse:
Service:
logout() {
// you should consider providing a type
return this.http.post(this.logOutApi, null, { observe: 'response' });
}
Component:
logout() {
this.chk.logout().subscribe(
(res) => {
if (res.status == 200) {
console.log(res);
})
}
}, (err) => {
alert("There was a problem logging you out");
});
}
Hopefully that helps!