承诺未在Bluebird

时间:2017-01-05 12:12:39

标签: node.js promise bluebird

我收到的错误似乎表明我没有回复我的一些陈述,但我认为我正在做的一切正确。这是警告:

Warning: a promise was created in a handler at /src/api/podcasts.js:51:18 but was not returned from it

这是相关函数的代码:

  'findPodcastById': (db, podcastId, callback) => {
    var queryString = "SELECT * FROM podcasts WHERE id=$1;";
    db.one(queryString, [podcastId])
      .then((result) => {
        return callback(null, result);
      })
      .catch((err) => {
        return callback(err, null);
      });
  },

从中调用的父函数:

app.post('/getepisodes', (req, res, next) => {
  var podcastId = req.body.podcastId;
  var userId = req.body.userId;
  var podcast;
  podcasts.findPodcastByIdAsync(db, podcastId)
    .then((result) => {
      podcast = result;
      return request(podcast.rss);
    })
    .then((result) => {
      return podcastParser.parseAsync(result, {})
    })
    .then((result) => {
      return Promise.resolve(result.channel.items);
    })
    .map((item) => {
      var date = new Date(item.pubDate).toLocaleString();
      return podcasts.addEpisodeAsync(db, podcast.id, item.title, item.enclosure.url.split('?')[0], striptags(item.description), date, item.duration);
    })
    .map((episode) => {
      return posts.addPostAsync(db, 'podcast', episode.id, episode.title, episode.description);
    })
    .then(() => {
      return podcasts.findEpisodesByPodcastIdAsync(db, podcastId, userId);
    })
    .then((result) => {
      return res.json(result);
    })
    .catch((err) => {
      next(err);
    });
});

我在每个承诺块中都有一个return语句,所以我不确定我做错了什么,我真的很感激一些帮助!

1 个答案:

答案 0 :(得分:0)

findPostCastBy id没有返回promise,试试这个

'findPodcastById': (db, podcastId) => {
    return db.one("SELECT * FROM podcasts WHERE id=$1;", [podcastId])
}