Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django channels 2.0 websocketbridge.js 403 when self.code(code=1007)

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.

like image 952
Nav Avatar asked Nov 29 '25 13:11

Nav


1 Answers

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.

like image 148
Nav Avatar answered Dec 02 '25 05:12

Nav



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!