-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uncaught Error for declining connection initialization at "OnNameSpaceconnect" #7
Comments
Hello @mbecker and sorry for the delay, What do you mean by "the returned error should be caught and sent to the end user properly"? This is done on server's However, if you mean the issue is the error log you posted above then you should check the catch of |
Hi @kataras , I'm sorry the code above is just an extract from your example here in the repos. The full javascript code is as follows: async function runExample() {
// You can omit the "default" and simply define only Events, the namespace will be an empty string"",
// however if you decide to make any changes on this example make sure the changes are reflecting inside the ../server.go file as well.
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: function(nsConn, msg) {
addMessage("disconnected from namespace: " + msg.Namespace);
},
vehicles: function(nsConn, msg) {
// "vehicles" event.
addMessage(msg.Body);
}
}
},
{
headers: {
"X-Username": username
}
}
);
// You can either wait to conenct or just conn.connect("connect")
// and put the `handleNamespaceConnectedConn` inside `_OnNamespaceConnected` callback instead.
// const nsConn = await conn.connect("default");
// nsConn.emit(...); handleNamespaceConnectedConn(nsConn);
conn.connect("default");
} catch (err) {
handleError(err);
}
}
function handleError(reason) {
console.log(reason);
window.alert("error: see the dev console");
} Thanks for the explanation in your first paragraph. My use case is to restrict just specific namespace on the backend; that's why I'm returning an error on the server's websocket.OnNamespaceConnect as follows: websocket.OnNamespaceConnect: func(nsConn *websocket.NSConn, msg websocket.Message) error {
return fmt.Errorf("No role 'admin'")
} I mean with the following sentences
that the returned error The sequence would be as follows: Javascript Client -> Connection to WS Server Namespace -> WS Server returns error for establishing connection to namespace -> Send back error to client -> Client catches error Maybe I'm missing something. Any help or hint would be awesome. Thanks! |
Hi,
I'm declingin the initialiation the connection of the websocket to a namespace as follows:
At the client side the connection initialization is from the examples as follows:
The error from the js library is as follows:
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?
The text was updated successfully, but these errors were encountered: