handle an empty POST request to my api endpiont
This is my code:
if(req.body === undefined){
return res.status(500).json({
error: 'request body is NULL or empty',
});
}
But It is not working. What I receive is a default mongoose error which is after this code.
How can I fix this? ,
I am using Postman to send an empty request even without headers, how to handle that?
It's likely req.body is populated as an empty object
if(!req.body)
Are you using body parser?
More to that, make sure you pass correct headers to postman!
Hi guys, please help, I still didn't find solution for this problem, how to do that elegantly?
Обсуждают сегодня