Bluebird promisifyAll和Node" oauth"库,回调函数预期

时间:2017-09-22 08:36:12

标签: node.js oauth promise bluebird

尝试使用Bluebird promisifyAll来包装oauth的方法,如下所示:

const Promise = require('bluebird')
const OAuth = Promise.promisifyAll(require('oauth'), {
  multiArgs: true
}).OAuth

并像这样使用:

const result = await this.oauth.getOAuthAccessTokenAsync(
        // token,
        // tokenSecret,
        // verifier
)

(注释掉强制错误的参数)

但是,我的应用程序崩溃了(从oauth lib中),而不是落到周围try / catch的catch块中:

if( error ) callback(error);
                     ^

TypeError: callback is not a function

我还需要做些什么来正确处理错误吗?

1 个答案:

答案 0 :(得分:0)

您需要 promisify 而非go test模块,但使用oauth创建的对象:

new OAuth.OAuth()

<强>更新

或者你可以宣传 const Promise = require('bluebird') const OAuth = require('oauth').OAuth; var oauth = new OAuth(); Promise.promisifyAll(oauth, { multiArgs: true }); ,因为 Ben Fortune 建议:

OAuth.prototype

Working example

相关问题