麻烦Meteor.wrapAsync和mailchimp-api-v3

时间:2016-12-05 19:46:03

标签: javascript meteor npm mailchimp

我试图在Meteor(1.4.1.3)项目中使用mailchimp-api-v3(我喜欢这个中的批量支持)

我已经把这个电话包裹在Meteor的.wrapAsync中(那里有一点学习曲线,但我认为我已经得到了它。)< / p>

我认为.wrapAsync的工作方式与作者编写mailchimp-api-v3包的方式之间存在冲突。

这是我的方法:

var Mailchimp = require('mailchimp-api-v3')

Meteor.methods({

getCampaigns: function() {
    console.log("running...");

    var mailchimp = new Mailchimp(Meteor.settings.private.mailChimp.apiKey); 

    var getCampaignsAsyncToSync = Meteor.wrapAsync(mailchimp.request, mailchimp);
    var resultOfGetCampaigns = getCampaignsAsyncToSync({method: 'get', path: '/campaigns'}, {});

    var campaigns = [];

    _.each(resultOfGetCampaigns.campaigns, function(campaign){
        var doc = {
            //Just grab a few pieces of data for testing
            id: campaign.id,  
            type: campaign.type,
            create_time: campaign.create_time
        };

        campaigns.push(doc);
    });

    return campaigns;
}
});

控制台错误结果:

=> Meteor server restarted
I20161205-14:32:22.908(-5)? running...
W20161205-14:32:24.134(-5)? (STDERR) Unhandled rejection TypeError: done is not a function
W20161205-14:32:24.135(-5)? (STDERR)     at /Users/michaelwickett/Sites/sagecomm-projects/academica-reporter/node_modules/mailchimp-api-v3/index.js:507:9
W20161205-14:32:24.135(-5)? (STDERR)     at processImmediate [as _immediateCallback] (timers.js:383:17)
W20161205-14:32:24.135(-5)? (STDERR) From previous event:
W20161205-14:32:24.135(-5)? (STDERR)     at Mailchimp.request (/Users/michaelwickett/Sites/sagecomm-projects/academica-reporter/node_modules/mailchimp-api-v3/index.js:506:13)
W20161205-14:32:24.136(-5)? (STDERR)     at packages/meteor/helpers.js:118:1
W20161205-14:32:24.136(-5)? (STDERR)     at [object Object].getCampaigns (server/methods.js:11:36)
W20161205-14:32:24.136(-5)? (STDERR)     at maybeAuditArgumentChecks (packages/ddp-server/livedata_server.js:1711:12)
W20161205-14:32:24.136(-5)? (STDERR)     at packages/ddp-server/livedata_server.js:711:19
W20161205-14:32:24.136(-5)? (STDERR)     at [object Object]._.extend.withValue (packages/meteor/dynamics_nodejs.js:56:1)
W20161205-14:32:24.136(-5)? (STDERR)     at packages/ddp-server/livedata_server.js:709:40
W20161205-14:32:24.137(-5)? (STDERR)     at [object Object]._.extend.withValue (packages/meteor/dynamics_nodejs.js:56:1)
W20161205-14:32:24.137(-5)? (STDERR)     at packages/ddp-server/livedata_server.js:707:46
W20161205-14:32:24.137(-5)? (STDERR)     at Session.method (packages/ddp-server/livedata_server.js:681:23)
W20161205-14:32:24.137(-5)? (STDERR)     at packages/ddp-server/livedata_server.js:551:43

我发现此线程Meteor - Wrapping NPMs with Meteor.wrapAsync似乎有关,但我不太了解故障排除,或手动覆盖程序包的设置方式。依赖!

我想了解,因此我的问题。

感谢您的阅读时间,并为我提供正确的方向。

1 个答案:

答案 0 :(得分:1)

您不需要使用.wrapAsync,您使用的包支持Promise和Meteor方法可以很好地使用它。请参阅:How to return from remote API call in Meteor Method?