那么不是函数承诺错误



我是承诺的新手,我使用蓝鸟文档从异步代码中获取数据

我尝试的是以下内容:

错误是:

getToken.then不是函数

我怎样才能避免它?

此文件连接.js

return connection.getToken.then(function(connToken){
console.log(connToken);
}).catch({

})

这是模块B中getToken的代码

const request = require("request-promise");
const Promise = require("bluebird");
module.exports = {

getToken: function () {

return new Promise((resolve, reject) => {
let options = {
method: 'POST',
url: 'https://authentication.arc.com/oauth/token',
headers: {
grant_type: 'client_credentials',
authorization: 'Q0MDdmMCFiMTc0fGNvlQVRDWThDNDFsdkhibGNTbz0=',
accept: 'application/json;charset=utf-8',
'content-type': 'application/x-www-form-urlencoded'
},
form: {
grant_type: 'client_credentials',
token_format: 'opaque&response_type=token'
}
};

request(options)
.then(function (body) {
return body;
})
.catch(function (err) {
return err;          
});
})
}
}

你需要实际调用该函数。

连接.js

return connection.getToken() // note the parentheses ()
.then(function(connToken){
console.log(connToken);
})
.catch(function(error){
console.error(error);
});

相关内容

最新更新