Best way to handle WebSocket errors in Django Channels without closing the connection? #2191
Unanswered
damnNepali
asked this question in
Q&A
Replies: 1 comment
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Hey everyone 👋
I’m building a WebSocket-based feature using Django Channels, and I’m a bit confused about best practices for error handling.
Let’s say I’m processing messages in my consumer — if something fails (like invalid data), what’s the cleanest way to send the error back to the client without closing the WebSocket?
I tried using try/except and sending an "error" message manually, but I’m not sure if that’s considered good practice.
Also, how do you properly handle exceptions during connection/authentication (so it closes gracefully)?
Would love to hear how others are doing it 🙏
All reactions