Goal: If the server response with 200 code, I want to perform some changes on the record locally.
issue: I am not able to access the response code or the 'message' attribute
this is how the server response from this http call::
// MongooseModelSchema: this is the model that uses moongose
MongooseModelSchema.updateOne({ _id: req.params.id, creator: req.userData.userId }, channel)
.then(result => {
if (result.n > 0) {
res.status(200).json({ message: "Update successful!" }); // this is what I want to capture
} else {
res.status(401).json({ message: "Not authorized!" });
}
})
.catch(error => {
console.log(error);
res.status(500).json({
message: "Couldn't udpate channel!"
});
});
I am able to hit the API no problem
I have the following http snip in my angular code::
this.http
.put(BACKEND_URL+'setState/' + id, channelData)
.subscribe(response => {
console.log('response',response);
console.log('check if response has Update successful!: ',JSON.stringify(response).search('Update successful!'));
console.log('response.message',response.message);
this.router.navigate(["/editChannel", id]);
})
this is the console.log image:
issue image: as you can see, i dont have access to the return code. I also cant access the 'message' property UNTIL i run the code, then it works.... super weird.
How do I check for the 200 code?