node-express-sequelize-es2015 icon indicating copy to clipboard operation
node-express-sequelize-es2015 copied to clipboard

Some bluebird warinings with un-returned promise

Open deksden opened this issue 8 years ago • 0 comments

I ve got some bluebird warnings like "Warning: a promise was created in a handler at ... but none were returned from it" - for ex, code in auth.js:

const strategy = new Strategy(params, (payload, done) => {
    Users.findById(payload.id)
        .then(user => {
          if (user) {
            return done(null, { // << -- here is problem
              id: user.id,
              email: user.email,
            });
          }
          return done(null, false);
        })
        .catch(error => done(error, null));
  });

Here is explanation of problem in issue thread: https://github.com/petkaantonov/bluebird/issues/508

Possible fix:

const strategy = new Strategy(params, (payload, done) => {
    Users.findById(payload.id)
        .then(user => {
          if (user) {
            return { // << -- fix 
              id: user.id,
              email: user.email,
            });
          }
          return false;
        })
        .asCallback(done)
        .catch(error => done(error, null));
  });

deksden avatar Jun 26 '17 04:06 deksden