Skip to content

Websocket error on HTTP Operation #20

Description

@yanover

Hey guys !

I’m building a web interface to manage my LXD containers. I use the lxd-node library to make my requests.

I can get my hosts and containers, stop, start or restart them but when it comes to sending commands, it doesn’t work.

I know that the node-lxd project is no longer maintained and I hesitate to create my requests directly by querying the LXD API but I would still like your feedback :

This is my function to send a command, I took the same example as in the official documentation, I just retrieve my container with an external function (which is working) :

public async execute(
    host: HostDto,
    container: ContainerDto,
    command: CmdDto,
  ) {
    let target = await this.getContainer(host, container);

    target.exec(['sleep', '5'], (err, process) => {
      if (err != null) {
        console.error(err);
        return;
      }

      process.on('close', () => {
        console.log('process closed');
      });
    });
  }

Unfortunately, my server is saying :

Error: unexpected server response (400)
    at ClientRequest.response (D:\Programation\Nasticot\NAS-SERVER\project\node_modules\ws-unix\lib\WebSocket.js:704:15)
And this part of the Websocket library is the following :
if (!self.emit('unexpected-response', req, res)) {
    error = new Error('unexpected server response (' + res.statusCode + ')');
    req.abort();
    self.emit('error', error);
 }

I probably miss something … If anyone has an idea, it would be very appreciated !

Thank you

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions