adonis-websocket
adonis-websocket copied to clipboard
How to close socket connection via middleware?
Dear, I do the example follow: https://adonisjs.com/docs/4.1/websocket-server#_creating_middleware, and I modify some code like bellow
'use strict'
class CustomMiddleware {
// for HTTP
async handle (ctx, next) {
}
// for WebSocket
async wsHandle (ctx, next) {
ctx.socket.close() // I wan to close socket connection before it go to my ChatController
}
}
module.exports = CustomMiddleware
But it not woking, socket never close. Is it bugs or what am I doing wrong?
I using adonisjs 4.1. my node version is 10.x
You have to use throw error like this to stop the process and catch it from the client side
throw new Error('Some authentication error')