I'm using API coded in NodeJS but always Postman identify HttpStatus 200, even when i send 4XX or other.
I'm using express and body-parser
The code is:
router.get('/', async(req, res) => {
try{
let dados = await busca(0);
let pasta = '/upload/'
let nomearquivo = '';
var contents = '';
if (dados){
for (const [idx,row] of dados.entries()){
nomearquivo = pasta + row.arquivotitulo;
if (fs.existsSync(nomearquivo)){
contents = fs.readFileSync(nomearquivo, {encoding:'base64'});
dados[idx]['arquivotitulo64'] = contents;
}
}
return res.status(200).send(dados);
}else{
return res.sendStatus(404);
}
}catch (err){
console.log(err);
return res.sendStatus(500);
}
});
Can anyone help me to send correctly resposes that turns possible to identify in Postman the correct Status code?
Try like this res.status(404).send('Not Found');
It should work and straightforwrd