socket.io – can’t receive “next(new Error())” event in Android client?

3 views
0

In my node JS backend I have some pretty simple authentication for my socket.io

io.use(async function (socket, next) {
        try {
            socket.decoded = await db.verifyAuthToken(socket.handshake.query.token, io.secret);
            next();
        }
        catch (err) {
            console.error("Socket error validating JWT: " + err);
            socket.disconnect();
            next(new Error("Socket auth error: No token provided"));
        }
    });

So accordingly to my logs, the error is successfully caught and handled. In my client (Android) I have listeners for both the error and connect_error event:

mSocket.on("error", new Emitter.Listener() {
                @Override
                public void call(Object... args) {
                    Log.e(this.getClass().getName(), Arrays.toString(args));
                }
            });

mSocket.on("connect_error", new Emitter.Listener() {
                @Override
                public void call(Object... args) {
                    Log.e(this.getClass().getName(), Arrays.toString(args));
                }
            });

However, after debugging, I realize that neither of those events are called when my backend does a next(new Error()) call. What could be wrong here? I want my client to be able to successfully receive this error. The socket otherwise works normally when emitting/receiving events.