I am wondering how to throw an error or returning value from event.
My code looks like this:
_initConnection(){
try{
const errorValidation = this.errorValidation
const HOST = "192.168.2.32"
const PORT = 8282
this.socket = net.createConnection(PORT, HOST)
this.socket.on('data', function(data) {
errorValidation(data)// throwing error
console.log('Received: ' + data);
return data
});
this.socket.on('err', function(err) {
console.log('Connection'+err);
});
this.socket.on('close', function(e) {
console.log('Connection closed');
});
}catch(err){
throw err
}
}
But because of the event throwing error is impossible it crash the app what should I do? Is using a Promies is a good guess?