glpi-project / node-module-glpi

Node client to interact with GLPI API REST
https://glpi-project.github.io/node-module-glpi/
GNU General Public License v3.0
8 stars 9 forks source link

Wrong way to use promises #36

Open MartialSeron opened 6 years ago

MartialSeron commented 6 years ago

Considering your code with promises in README.md, I wonder if you understand how we use them? You take the path to the pyramid of doom.

This is the correct way to use promises :

const client = new GlpiRestClient(config.apirest);
client.initSessionByCredentials(config.user.name, config.user.password, config.appToken)
.then((res) => {
  // Do your stuff here
  return client.getActiveProfile();
})
.then((res) => {
  // Do your stuff here
  return client.killSession();
})
.catch((err) => {
  console.log(err);
});

hth

Gianfranco97 commented 6 years ago

@MartialSeron Thank you very much for the feedback, we will take it into account to update our code examples.