I'm using Node JS application that connects to Kakfa using kafka-node. I'm catching some exceptions is there is any errors in connecting to kafka. Here is the code. I'm getting can't set headers after they are sent. What is the best way to avoid this?
// Some processing goes above
producer.on('error', function(err){
console.log(err);
res.status(500).send("Oh uh, something went wrong");
})
res.end();
I'm pretty sure it is because code is continuing after the error loop. How can I avoid this situation without removing send in error handler.