Похожие чаты

Hey hi guys, I need a help,I am trying to

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?

5 ответов

3 просмотра

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!

Siva Rama Krishnan-C Автор вопроса

Hi guys, please help, I still didn't find solution for this problem, how to do that elegantly?

Похожие вопросы

Обсуждают сегодня

Карта сайта