我不确定问题是什么......它可能与我的承诺处理有关 . 这是一个nodejs / express应用程序 . 我正在使用Sequelize.js与我的数据库进行交互,它使用了promises .

基本上,用户可以在下面发布帖子请求 .

现在, condition1 工作正常 . condition3 也行得正常 . 但是,如果结果是 condition2 ,则将执行console.log消息 Condition 2 success! ,但 res.send('success2!'); 代码将不会执行...代码将挂起 .

router.post('/checkUserRoute', function(req, res, next) {

    const username = req.body.username;
    if (condition1) {
        userTable.findOne({
            where: {
                username: username
            }
        }).then(function(user) {
            if (condition2) {
                console.log('Condition 2 success!')
                res.send('success2!');
            }
            if (condition3) {
                user.update({
                    username: 'NewUserName' 
                }).then(function() {
                    console.log('Condition 3 success!');
                    res.send('success3!');
                });
            }
        }).catch(function(err){
            res.send('error');
        });
    }
});

当满足 condition2 并且它到达 res.send('success2!'); 行时,我的终端中会显示以下消息:

Warning: a promise was created in a handler at anonymous> ... but was not returned from it, see 然后显示以下链接:

http://bluebirdjs.com/docs/warning-explanations.html#warning-a-promise-was-created-in-a-handler-but-was-not-returned-from-it

该链接建议添加 return ,但这没有帮助 .