I have some middleware I wrote to throw a new error when a JWT isn't present. I have placed a throw new Errror directly inside the middleware, so it always throws an error.
The error never arrives on the client (using the client api from socket-io).
The UI - I am listening to all possible events and they seem to work but I get NO error or any event when i throw the new Error on the node layer.
Here is the code on the node layer
this.socketServer = socketIO(this.httpServer)
this.socketServer.use((socket, next) => {
// var token = socket.handshake.query.auth_token
return next(new Error("Authentication error"))
})
and here is the ui
this.socket = new io.Manager(this.configService.getConfig().serverUri as any, {
query: "auth_token=THE_JWT_TOKEN"
})
this.socket.on("connect_error", (a: any, b: any, c: any) => {
debugger
})
this.socket.on("disconnect", (err: any) => {
debugger
})
this.socket.on("reconnect", (a: any, b: any, c: any) => {
debugger
})
this.socket.on("reconnect_attempt", (a: any, b: any, c: any) => {
debugger
})
this.socket.on("reconnecting", (a: any, b: any, c: any) => {
this.socket.opts.query = "auth_token=CHANGE_JWT"
})
this.socket.on("error", (a: any, b: any, c: any) => {
debugger
})
Throwing an error inside the socket-io middleware in node should trigger some kind of event inside the UI - so that I am able to respond with it ... But it does not.
socket.io version:
"socket.io": "2.1.1",
"socket.io-client": "2.1.1",
You are only creating an error, not throwing it ...
Use throw
, do not use next()