0

您好我已经编写了以下与 qliksense 服务器通信并使用节点 JS 将 QVF 文件转换为 json 的代码。当我尝试这样做时,我收到以下错误。

(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)
    }
})

请帮我解决这个问题

4

1 回答 1

1

你有很多奇怪的事情发生,比如async结合使用.then()

我试图清理代码async / await

ipcMain.on("migration:qlik", async (w, options) => {
  try {
    var options = JSON.parse(options);
    let data = await Promise.all(
      options["application_info"].map(async appToBeMig => {
        let certificates = await qvfToJson.qvfToJson();
        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}`
              }
            })
        });
        let global = await session.open();
        let doc = await global.openDoc(appToBeMig["app_id"]);
        let appData = await serializeapp(doc);
        await session.close();
        return appData;
      })
    );
    console.log(data);
  } catch (err) {
    console.log(err);
  }
});
于 2020-11-19T08:53:02.697 回答