if error occurs in first function i.e mw1 error msg in response & response is end but, i don't want node to process that req further after sending response, but now the next function mw2 executes after sending response. which gives error cant set header. i tried next('route') but no use. please suggest how to get this done.
function mw1(req, res, next){
if(req.id == 1){
res.status('500');
res.json({
STATUS: "error",
http_code: '500',
msg: 'function 1',
error_code: ''
});
res.end();
}
next();
}
function mw2(req, res, next){
if(req.id == 2){
res.status('500');
res.json({
STATUS: "error",
http_code: '500',
msg: 'function 2',
error_code: ''
});
res.end();
}
next();
}
function mw3(req, res, next){
if(req.id == 3){
res.status('500');
res.json({
STATUS: "error",
http_code: '500',
msg: 'function 3',
error_code: ''
});
res.end();
}
next();
}
app.use('/sub', mw1);
app.use('/sub', mw2);
app.use('/sub', mw3);