Uncaught Error for declining connection initialization at "OnNameSpaceconnect"
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 40
- Forks
- 16
- PR merge metrics
- No merged PRs in 30d
Description
Hi,
I'm declingin the initialiation the connection of the websocket to a namespace as follows:
var serverEvents = websocket.Namespaces{
namespace: websocket.Events{
websocket.OnNamespaceConnect: func(nsConn *websocket.NSConn, msg websocket.Message) error {
return fmt.Errorf("No role 'admin'")
},
websocket.OnNamespaceConnected: [...]
At the client side the connection initialization is from the examples as follows:
async function runExample() {
try {
const conn = await neffos.dial(
wsURL,
{
default: {
// "default" namespace.
_OnNamespaceConnect: function(nsConn, msg) {
console.log(nsConn);
console.log(msg);
},
_OnNamespaceConnected: function(nsConn, msg) {
addMessage("connected to namespace: " + msg.Namespace);
handleNamespaceConnectedConn(nsConn);
},
_OnNamespaceDisconnect: [...]
The error from the js library is as follows:
Uncaught (in promise) Error: No role 'admin'
at deserializeMessage (neffos.min.js:1)
at a.handleMessage (neffos.min.js:1)
at a.handle (neffos.min.js:1)
at WebSocket.i.onmessage (neffos.min.js:1)
My use case is that I want only allow specific users the connection to a websocket namespace. On the client side the returned error should be caught and sent to the end user properly.
Did I cancel the initialization of the websocket connection to the namespace in the correct way?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing deserializeMessage and handleMessage in neffos.min.js, then compare the namespace connection error path with the client callbacks shown in the issue. Done means a rejected namespace initialization can be handled by the client without an uncaught promise error, while preserving the server's "No role 'admin'" message.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- networking
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100