Web socket connection returns an empty error

Hello,
I have a problem when I am trying to make a WebSocket connection between a plugin and our tool. Actually, the ws.onerror returns an empty error without the reason of the WebSocket connection error (e.g the response is { } ).
Does anyone have the same issue?

this is the code:

  const webSocketPath = `ws://localhost:${portNumber}/`;
  const ws = new WebSocket(webSocketPath);

  // Connection opened
  ws.onopen = async event => {
    this.ws = ws;
    resolve();
  };

  ws.onerror = event => {
    console.log(event) // returns only {}
    reject();
  };