Hai Saya telah menulis kode berikut yang berkomunikasi dengan server qliksense dan mengonversi file QVF sebagai json menggunakan node JS. Ketika saya mencoba melakukannya, saya mendapatkan kesalahan berikut.

(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.

Silakan temukan kode di bawah ini yang saya gunakan

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

Tolong bantu saya menyelesaikan masalah ini this

0
saran k 19 November 2020, 11:36

1 menjawab

Jawaban Terbaik

Anda memiliki banyak hal aneh yang terjadi seperti menggunakan async dalam kombinasi dengan .then()

Saya mencoba membersihkan kode dengan 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);
  }
});
1
Ifaruki 19 November 2020, 08:53