I am running django channels 2.0 for a chat room. During connect, I check the room name. If it does not exist, I reject the connection using self.code(code=1007). The ASGI logs show a successful reject as below:
WebSocket REJECT /ws/discuss/asdf/asdf1
However, on the client side the js library websocketbridge (stock from the installation) throws an unexpected exception, as below:
Error during WebSocket handshake: Unexpected response code: 403
On printing to console the received argument. I get the following:
CloseEvent {isTrusted: true, wasClean: false, code: 1006...
I would like to catch the error code 1007 thrown by the consumer in the front end, so that I can handle the rejection gracefully.
Any help will ge greatly appreciated.
Thanks in advance.
The mistake I was making is that in the connect method of the consumer, I was not accepting the questions by using self.accept(). I first accepted the connection and after evaluating conditions issued a self.close(code=4004). I maybe wrong, but I would expect to not accept the connection, till the conditions are met.
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