1

I am getting an error that seems to suggest I'm not returning some of my statements, but I think I'm doing everything correctly. Here's the warning:

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

This is the code of the function in question:

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

And here is the full series of callbacks in the parent function:

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);
    });
});

There is a return statement in each promise block so I'm not sure where I'm going wrong.

Dan
  • 2,647
  • 2
  • 27
  • 37
  • Looks like `callback` is the problem. Try this version of `getPodcastById` function: `'findPodcastById': (db, podcastId) => { var queryString = "SELECT * FROM podcasts WHERE id=$1;"; return db.one(queryString, [podcastId]) },` – dfsq Jan 09 '17 at 14:29
  • Are you ever using the `callback`? You should remove that parameter and use `podcasts.findPodcastByIdAsync(db, podcastId).asCallback(callback)` instead. Also, are you sure that `/getepisodes` is where you get the error? Check the stack trace of the warning. – Bergi Jan 09 '17 at 14:31

0 Answers0