I am currently working on a first MERN fullstack (using mongoose).
I am trying to cover all possible errors, including server side errors, and notifying the client. For example: I am trying to run the app while my local MongoDB server is not running, to find that specific error, and catch it.
So of course there is an error, but it seems like the .catch
after the EventNote.find
(EventNote is the mongoose model) doesn't catch it, and certainly does not send it back to the client (ideally a modal will pop up).
Any help will be appreciated!
Note: The app and the route- they all work exactly as expected, so a req does reach the route, and normally does send back the expected data.
router.get("/get_events_by_month/:month", (req, res) => {
const { month: query } = req.params;
EventNote.find({ month: query })
.then(data => {
res.status(201).send(data);
})
.catch(err => {
console.log(err);
res.status(500).send(err);
});
});