[英]Results from Bluebird promisified library is returned as an error
我目前正在将Bluebird与fb npm软件包一起使用。
我设法使fb库返回数据。 但是,数据被捕获为错误,而不是传递给then()
方法。
var Promise = require('bluebird'), fb = Promise.promisifyAll(require('fb')); fb.apiAsync(endPoint, options) .then(function(response) { console.log(response); // This doesn't get called }, function(e) { console.log(e); // The facebook response gets returns as part of the error instead });
我是否以错误的方式使用了诺言? 到目前为止,我已经尝试遵循Bluebird页面上的文档。
缺省情况下,bluebird中的promisify
函数期望回调API为:
查看npm上的fb
包,我们可以看到回调使用以下形式:
function (res) { ...}
回调函数的第一个参数是结果,而错误值似乎没有参数。 这意味着此API违反了规则2和3。 幸运的是,bluebird允许用户编写自定义的promisifier函数,有关详细信息,请参阅bluebird API 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.