【发布时间】:2020-11-19 08:36:25
【问题描述】:
您好,我编写了以下与 qliksense 服务器通信并将 QVF 文件转换为 json 的代码 使用节点 JS。当我尝试这样做时,出现以下错误。
(node:21220) UnhandledPromiseRejectionWarning: #<ErrorEvent>
(node:21220) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:21220) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
请找到我正在使用的以下代码
ipcMain.on('migration:qlik',async(w,options)=>{
try
{
console.log("********************************* Qlik to PBI *****************************")
var options = JSON.parse(options)
console.log(options)
options['application_info'].map((appToBeMig)=>{
qvfToJson.qvfToJson()
.then((certificates)=>{
console.log(certificates)
var server = store.get('qlik_server')
var userDir = store.get('qlik_user_dir')
var userID = store.get('qlik_user_id')
let session = enigma.create({
schema,
url: `wss://${server}}:4747/app/engineData`,
createSocket: url => new WebSocket(url, {
ca: certificates.root,
cert: certificates.cert,
key: certificates.key,
headers: {
'X-Qlik-User': `UserDirectory=${userDir}; UserId=${userID}`
}
}),
})
session.open().then((global) => {
global.openDoc(appToBeMig['app_id']).then((doc)=>{
serializeapp(doc)
.then((appData)=>{
session.close().then(() => console.log("session closed"))
console.log(JSON.stringify(appData))
// resolve(JSON.stringify(appData))
// console.log(appData.properties)
// let data = JSON.stringify(result);
// var appName = utils.cleanString(appData.properties.qTitle);
// fs.mkdir(appName, function(result)
// {
// writeFiles(appData, appName, '527d85fa-f33f-4437-8a91-26d450941e73');
// session.close()
// })
})
});
});
}).catch(function(){console.log("Error")})
})
}
catch(err)
{
console.log(err)
}
})
请帮我解决这个问题
【问题讨论】:
-
你的代码中有很多奇怪的东西。我强烈建议您了解承诺链,并可能将所有内容切换为使用
await而不是.then()。 -
我看你不知道
async有什么用/有什么用。你有很多.then()女巫,你可以通过使用await来避免。
标签: node.js promise async-await qliksense enigma2