Javascript 并非在Array.map()调用中的async/await之后的所有元素都得到解析

Javascript 并非在Array.map()调用中的async/await之后的所有元素都得到解析,javascript,node.js,async-await,Javascript,Node.js,Async Await,我在早些时候发布了一个问题。它最后显示了将同步函数转换为异步函数后的一些输出;但是,在输出数组中,一些元素是空的。我不知道为什么 主代码如下所示: router.post('/form1', async (req, res, next)=>{ try{ const emdate = new Date(req.body.emdate); const address = req.body.address; const stationDataCursor = stat

我在早些时候发布了一个问题。它最后显示了将同步函数转换为异步函数后的一些输出;但是,在输出数组中,一些元素是空的。我不知道为什么

主代码如下所示:

router.post('/form1',  async (req, res, next)=>{

try{
    const emdate = new Date(req.body.emdate);
    const address = req.body.address;
    const stationDataCursor = stationData.filteredData(instantData, emdate);

    stationDataCursor.toArray().then(async (docArr)=>{


            return await Promise.all(docArr.map(async function(val, ind){

                try {
                    const feature = await calcDSV.calcDSV(val);                        
                    return feature

                } catch (error) {

                    console.log(ind);
                    console.log("Error happened in data array", error);

                }

            }));


    }).then((doc)=>{
        res.json(doc)
    })

} catch(error){
    res.status(400).send(error)
}
})
我尝试在
calcDSV(val)


我希望每个元素都能被解析。

多亏了这些注释,我才能够找到源代码:我定义的其他函数中的
抛出错误()。应该是
throw Error()

错误消息告诉您什么?关于读取堆栈错误的一点提示,首先出现的函数是您是否要开始查找。在本例中,它的
periodFunc.js
,不显示。
async function calcDSV(featuresJSON){

    // featuresJSON  
    const SVscore = [];
    const tuEval = featuresJSON.features.properties.TU90; // array
    const obArr = featuresJSON.features.properties.OB; // array
    const periodObj = await getPeriods(tuEval);// get period position
    const paramObj = await getParams(periodObj, obArr); // get parameters
    const periodDate =  await getPeriodDate(featuresJSON, periodObj);
    const removeTime =  periodDate.beginDate.map(x=>x.split('T')[0]);


    let hourly = paramObj.hourCounts;
    let avgTemps = paramObj.avgTemps;


    for(let i = 0;i<hourly.length; i++){

        let score = await assignScore(avgTemps[i], hourly[i]);
        SVscore.push(score);

    }

    // output sv score for date


    const aggreScore = await accumScore(removeTime, SVscore);


    aggreScore.DSVdate = aggreScore.Date.map(x=>new Date(x));


    featuresJSON.features.properties.periodSV = SVscore;
    featuresJSON.features.properties.Periods = periodDate;
    featuresJSON.features.properties.DSVscore = aggreScore;

    return  Promise.resolve(featuresJSON);
}


module.exports.calcDSV = calcDSV;
2
Error happened in data array ReferenceError: error is not defined
at getParams (/media/swaggyp1985/HDD4T/OSU_Projects_2017-2018/App_Projects/wallin_model/dev/dev_js/wallin-server/src/utils/periodFunc.js:145:9)
at Object.calcDSV (/media/swaggyp1985/HDD4T/OSU_Projects_2017-2018/App_Projects/wallin_model/dev/dev_js/wallin-server/src/utils/wallinLogic.js:842:32)
at processTicksAndRejections (internal/process/task_queues.js:86:5)
6
Error happened in data array ReferenceError: error is not defined
at getParams (/media/swaggyp1985/HDD4T/OSU_Projects_2017-2018/App_Projects/wallin_model/dev/dev_js/wallin-server/src/utils/periodFunc.js:145:9)
at Object.calcDSV (/media/swaggyp1985/HDD4T/OSU_Projects_2017-2018/App_Projects/wallin_model/dev/dev_js/wallin-server/src/utils/wallinLogic.js:842:32)
at processTicksAndRejections (internal/process/task_queues.js:86:5)
...