I'm trying to throw and error server side when my websocket has more than 2 connections. I have this nice client-side onerror
method but I'm unable to reach that part of my code. I'm using nodeJS and the package ws
which has the smallest doc on error handling.
server.js
theWebSocketServer.on('connection', function connection(websocket){
if (theWebSocketServer.clients.length >2) {
// I want to throw the error here and pass it to onerror
console.log('No access allowed', theWebSocketServer.clients.length)
} else {
console.log('happy connection', theWebSocketServer.clients.length)
}
})
client.js
wsConnection.onerror = function(eventInfo) {
alert("There was a connection error!");
console.log("Socket error!", eventInfo);
}
How can I send an error to be handled on the client side JS?