I want to be able to emit an error packet to a client, similarly to how it's used when registering middleware.
This works:
var io = require('socket.io')();
io.use(function(socket, next){
if (socket.request.headers.cookie) return next();
next(new Error('Authentication error'));
});
This doesn't:
io.on('connection', function(socket){
socket.emit('error', {errorMessage: 'errorMessage'});
//or
socket.emit('error', new Error('error'));
});
Error: Uncaught, unspecified "error" event.
How do I emit an error event using the socket object?
Event name 'error' is reserved for transport level errors. When you will try
io.on('connection', function(socket){
socket.emit('exception', {errorMessage: 'errorMessage'});
});
it should work just fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With