1
votes

I want to connect an js socket client to socket.io server using socket = io.connect(). But on server side i m using io.use() method to check whether this socket connection contains cookies or not. I restrict the request on socket server to make connection if socket initial handshake does not contain cookies. by passing next(new Error("Authentication Error")). But i m not able to catch this error on client side. I want to notify the client of invalid login session and login again.

Thanks

2

2 Answers

2
votes

Thanks Andrey... I got success with

socket.on("error", function()
{
   //function to perform on occurance of authorisation failure
})
1
votes

I think you need to listen on connect_error:

socket.on('connection_error', function(data) {
    // data here should be an Error object sent by server
});

The documentation is awful, but here is a little hint (found here):

Errors passed to middleware callbacks are sent as special error packets to clients.