I'm pretty sure this should be a simple thing to fix but I have no idea why its happening, I'm using nodejs and mongodb here.
This is the route I'm calling and when I do that it simply returns 404 with an empty object. I'm sure this is not because it cant find the user with the email adress because userFound will be null in that case. But I couldn't find why its directly catching an empty error or something?
router.post("/notify", function (req, res) {
User.findOne({ email: req.body.email }).then((userFound) => {
const notification = {
type: req.body.type,
title: req.body.title,
description: req.body.description,
};
notification.destination = userFound;
Notification.save(function (err, notification) {
if (err) {
console.log(err);
res.status(500).send();
} else {
res.send(notification);
}
});
})
.catch((error) => {
return res.status(404).json(error);
});
});
I'm sorry I really feel stupid asking this.. Thanks for the help in advance.