SailsJS | TypeError: Cannot read property 'then' of undefined

javascript sails.js q

279 просмотра

1 ответ

I get this error when I 'GET' this controller action:

TypeError: Cannot read property 'then' of undefined

Code:

allUsers: function (req, res) {
    Admin.find({ id: req.adminId }, function (err, admin) {
      console.log(admin);
    })
    .then(function onSuccess(admin) {
      return User.find(function (err, users) {
        res.json(users);
      });
    })
    .catch(function onError(res) {
      return res.status(401).send();
    });
  }

Any thoughts?

Автор: CiscoKidx Источник Размещён: 08.11.2019 11:08

Ответы (1)


1 плюс

Решение

Seems like you are trying to mix callback and promise style here. What happens if you delete the part:

, function (err, admin) {
    console.log(admin);
}

According to Sails.js ORM documentation, the promise style find is crafted like this:

Zookeeper.find()
.then(function (zookeepers) {...})
.catch(function (err) {...});
Автор: Manuel Reil Размещён: 20.08.2016 08:15
Вопросы из категории :
32x32