GithubHelp home page GithubHelp logo

422 error about nodeactyl HOT 5 OPEN

nodeactyl avatar nodeactyl commented on May 26, 2024
422 error

from nodeactyl.

Comments (5)

thewillft avatar thewillft commented on May 26, 2024

Hey, if I had to guess you're missing 1 or more required inputs when creating a server. Try the following snippet below and see if anything changes:

router.get('/newserver', checkAuth, async function(req, res) {
  const pteroData = await client.getUserByEmail(req.user.email);
  const server = new Nodeactyl.ServerBuilder()
    .setServerName(req.query.name)
    .setServerOwner(pteroData.attributes.id)
    .setServerEgg(parseInt(req.query.egg))
    .setServerLimitsJson({
      memory: parseInt(req.query.ram),
      disk: parseInt(req.query.disk),
      cpu: parseInt(req.query.cpu),
      io: 500,
      swap: 0,
    })
    .createServer(client).then(response => {
      console.log(response);
      res.redirect('/shop');
    });
});

I'm thinking the issue lies in the .setServerLimitsJson argument you were giving (should be an object not a string). I also removed the separate server.function() calls and chained them together instead which is part of what makes the ServerBuilder so powerful. Let me know if this helps.

from nodeactyl.

ScopesCodez avatar ScopesCodez commented on May 26, 2024

I got this error when I copy pasted your code:

      .setServerOwner(pteroData.attributes.id)
      ^

TypeError: Cannot read properties of undefined (reading 'setServerOwner')

So I changed it a bit to this:

router.get('/newserver', checkAuth, async function(req, res) {
    const pteroData = await client.getUserByEmail(req.user.email);
    const server = new Nodeactyl.ServerBuilder()
    server.setServerName(req.query.name)
    server.setServerLimitsJson({
        memory: parseInt(req.query.ram),
        disk: parseInt(req.query.disk),
        cpu: parseInt(req.query.cpu),
        io: 500,
        swap: 0,
      })
    server.setServerOwner(pteroData.attributes.id)
    server.setServerEgg(parseInt(req.query.egg))
    server.createServer(client).then(response => {
        console.log(response);
        res.redirect('/shop');
      });
  });

and I still am getting the same 422 error.

from nodeactyl.

thewillft avatar thewillft commented on May 26, 2024

Hi, the following mocked example worked successfully for me:

(async () => {
  const req = {
    user: {
      email: 'email of existing user',
    },
    query: {
      name: 'My new server',
      ram: 512,
      disk: 512,
      cpu: 100,
      egg: 5,
    },
  };
  const pteroData = await client.getUserByEmail(req.user.email);
  const server = new Nodeactyl.ServerBuilder();
  server.setServerName(req.query.name);
  server.setServerLimitsJson({
    memory: parseInt(req.query.ram),
    disk: parseInt(req.query.disk),
    cpu: parseInt(req.query.cpu),
    io: 500,
    swap: 0,
  });
  server.setServerOwner(pteroData.attributes.id);
  server.setServerEgg(parseInt(req.query.egg));
  server.createServer(client).then(response => {
    console.log(response);
  });
})();

The only changes I made to the code in your latest reply was removing the route and mocking the data you are pulling from the request object in order to ensure the code to create the server and the library were working successfully.

I would suggest investigating the code specific to your application that you posted in your last reply. If I had to guess one or more of the values you are trying to pull from req are not returning what you want. Ensure that the user you are retrieving by email is being found successfully and that all the other parts you are setting (name, limits, egg) are all being set to the values you expect them to be set to.

from nodeactyl.

dev-bun avatar dev-bun commented on May 26, 2024

Hi, the following mocked example worked successfully for me:

(async () => {
  const req = {
    user: {
      email: 'email of existing user',
    },
    query: {
      name: 'My new server',
      ram: 512,
      disk: 512,
      cpu: 100,
      egg: 5,
    },
  };
  const pteroData = await client.getUserByEmail(req.user.email);
  const server = new Nodeactyl.ServerBuilder();
  server.setServerName(req.query.name);
  server.setServerLimitsJson({
    memory: parseInt(req.query.ram),
    disk: parseInt(req.query.disk),
    cpu: parseInt(req.query.cpu),
    io: 500,
    swap: 0,
  });
  server.setServerOwner(pteroData.attributes.id);
  server.setServerEgg(parseInt(req.query.egg));
  server.createServer(client).then(response => {
    console.log(response);
  });
})();

The only changes I made to the code in your latest reply was removing the route and mocking the data you are pulling from the request object in order to ensure the code to create the server and the library were working successfully.

I would suggest investigating the code specific to your application that you posted in your last reply. If I had to guess one or more of the values you are trying to pull from req are not returning what you want. Ensure that the user you are retrieving by email is being found successfully and that all the other parts you are setting (name, limits, egg) are all being set to the values you expect them to be set to.

I tested your code and got the following as an error:
(node:1276674) UnhandledPromiseRejectionWarning: 422
(node:1276674) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 3)

from nodeactyl.

thewillft avatar thewillft commented on May 26, 2024

I tested the example again to be sure and it does in fact create a server and return the data without a 422 error. I am using the latest version of Nodeactyl (3.2.1). In the context of the example I posted it must be made sure that you change the req.user.email field with a valid user's email and the req.query.egg field with a valid egg id from the panel you are testing on.

const Nodeactyl = require('nodeactyl');
const client = new Nodeactyl.NodeactylApplication('your valid panel url', 'your valid api key');

(async () => {
  const req = {
    user: {
      email: 'existing user email',
    },
    query: {
      name: 'My new server',
      ram: 512,
      disk: 512,
      cpu: 100,
      egg: 5,
    },
  };
  const pteroData = await client.getUserByEmail(req.user.email);
  const server = new Nodeactyl.ServerBuilder();
  server.setServerName(req.query.name);
  server.setServerLimitsJson({
    memory: parseInt(req.query.ram),
    disk: parseInt(req.query.disk),
    cpu: parseInt(req.query.cpu),
    io: 500,
    swap: 0,
  });
  server.setServerOwner(pteroData.attributes.id);
  server.setServerEgg(parseInt(req.query.egg));
  server.createServer(client).then(response => {
    console.log(response);
  });
})();

This is the full example I used, including the declaration/initialization of the client variable (which must be set by you for testing).

from nodeactyl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.