Skip to content
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

Server Middleware returning next(new Error(.......)) is not sent to the client #1541

Open
MrDesjardins opened this issue May 20, 2022 · 0 comments
Labels
to triage Waiting to be triaged by a member of the team

Comments

@MrDesjardins
Copy link

Describe the bug

I have a middleware that returns an Error object in some particular situation. I see the error in the server's console but I do not see the error being sent to the client.

Server:"socket.io": "^4.5.0"
Client: "socket.io-client": "^4.5.0"

To Reproduce

Socket.IO server version: x4.5.0

Server

import { Event, Socket } from "socket.io";
import { ServiceLayer } from "../services/serviceLayer";
export const userActivateMiddleware =
  (serviceLayer: ServiceLayer, socket: Socket) =>
  async (event: Event, next: (err?: Error) => void) => {
    const user = socket.data.user;

    if (user === undefined) {
      return next(new Error("User Email Not validated"));
    } 
    return next();
  };

// Elsewhere:
socket.use(userActivateMiddleware(serviceLayer, socket));

Socket.IO client version: 4.5.0

Client

import { io } from "socket.io-client";

// Listeners
socket.on("connect_error", socketConnectError);
socket.on("error", socketError);

function socketError(err: any): void {
    console.log("Socket Error", err);
}
function socketConnectError(error: Error): void {
    console.log("socketConnectError", error);
}

// How the request starts
socket.emit(MsgUserPixelKind, message, (response: MsgUserPixelValidation) => {
    manageResponseFromMsgUserPixel(response);
});

Expected behavior
The emit is performed and the NodeJS Socket.io servers receive the request. I can set a breakpoint and see the request getting inside the middleware. In the case I am testing, a rejection, I see the code getting into the if and executing the return next(new Error("....."));. I am expected to get the client to be notified somehow (by the connect_error or error or by the callback. However, nothing.

Platform:

  • Device: Macbook Pro
  • OS: MacOS 12.1

Additional context
Looking at the Chrome's network ws tab, I see the request sent which collaborate that I can have the NodeJS server hit my breakpoint. However, no response. The callback is not called either.

@MrDesjardins MrDesjardins added the to triage Waiting to be triaged by a member of the team label May 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
to triage Waiting to be triaged by a member of the team
Projects
None yet
Development

No branches or pull requests

1 participant