Skip to content
This repository has been archived by the owner on Sep 27, 2021. It is now read-only.

How to close socket connection via middleware? #77

Open
phambinh217 opened this issue Mar 30, 2019 · 1 comment
Open

How to close socket connection via middleware? #77

phambinh217 opened this issue Mar 30, 2019 · 1 comment

Comments

@phambinh217
Copy link

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

@fokoz
Copy link

fokoz commented May 29, 2019

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')

@RomainLanz RomainLanz transferred this issue from adonisjs/adonis-fullstack-app May 31, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants