async.waterfall回调未定义

时间:2015-07-27 15:41:42

标签: javascript node.js async.js

我以前做过这件事,但我不知道出了什么问题。异步瀑布中第二个函数的回调未定义。我的代码如下。

async.waterfall([
                function(callback){

                     var body = "some json string"
                     var b = JSON.parse(body);
                     return callback(null, b);
                }
                , function(data, callback){
                    mongodb.somecollection({somequery}, function(err, res){
                    if(!err){
                    var returnObj = {
                        success:true, 
                        data:{
                            access_token: "user token", 
                            end_date: "some date"
                        }, 
                        msg: "some string",
                        ref_code: "user_id"
                    };
                        callback(null, returnObj);
                   }
                    else{
                        callback(err);
                    }
                    });
                }
            ], function(err, result){

                if(!err){
                    return reply(result).type('application/json').code(200)
                }
                else{
                    err.trace = err.stack;
                    logger.log('error', err);
                    return reply(helper.responseHelper.Error('Something went wrong. Try again.')).type('application/json').code(200);
                }
        });

我收到以下错误,其中在mongo回调中调用了第二个回调。

  

TypeError:未捕获错误:undefined不是函数

任何人都可以告诉我我做错了吗?

下面是堆栈跟踪。

Debug: internal, implementation, error
TypeError: Uncaught error: undefined is not a function
at /Users/audiocompass/Sites/api/controllers/users.js:776:12
at /Users/audiocompass/Sites/api/node_modules/mongodb/lib/mongodb/collection/core.js:588:7
at /Users/audiocompass/Sites/api/node_modules/mongodb/lib/mongodb/db.js:1195:7
at bound (domain.js:254:14)
at runBound (domain.js:267:12)
at /Users/audiocompass/Sites/api/node_modules/mongodb/lib/mongodb/db.js:1903:9
at bound (domain.js:254:14)
at runBound (domain.js:267:12)
at Server.Base._callHandler (/Users/audiocompass/Sites/api/node_modules/mongodb/lib/mongodb/connection/base.js:453:41)
at /Users/audiocompass/Sites/api/node_modules/mongodb/lib/mongodb/connection/server.js:487:18

0 个答案:

没有答案