首页 > 解决方案 > UnhandledPromiseRejectionWarning: TypeError: (intermediate value) is not a function

问题描述

我正在尝试使用 async/await 调用一个函数(findNextOper()),当我调用它时出现此错误:

(node:2748) UnhandledPromiseRejectionWarning: TypeError: (intermediate value) is not a function

我尝试在不同的位置添加分号,但没有奏效。我不知道如何解决它。

//This is where I call the function

function regFasiFineLav(pool,oper){
    return new Promise(async (resolve,reject,) => {
        ...
        let nextOper = await findNextOper(pool,op);
        ...
        resolve();
 })();
};

//This is the function precedeing the one that trigger the error(findNextOper).
//I pasted because maybe it is related in some way

function StringToTime(stringTime){
    return new Promise(async (resolve,reject) => {
        stringTime = stringTime.split(":");
        resolve(parseInt(stringTime[0])*3600 + parseInt(stringTime[1])*60 + parseInt(stringTime));
    })();
};

//This is the function causing the error
function findNextOper(pool,op){
    return new Promise(async (resolve,reject) => {
        let sql_query = "SELECT TOP 1 oper_num FROM jobroute WHERE job = '" + op.job + "' AND suffix = " + op.suffix + " AND oper_num > " + op.oper_num + " ORDER BY oper_num ASC";
        let result = (await pool.request().query(sql_query)).recordset;
        if(result.length === 0){
            resolve(0);
        }else{
            resolve(result[result.length-1]);
        }
    })();
};

我想按顺序执行所有这些功能,因为这个任务不能异步完成

标签: javascriptnode.jspromise

解决方案


问题是()以下Promise构造函数。删除()构造函数的以下调用。链接.catch()Promises 以避免UnhandledPromiseRejectionWarning错误。


推荐阅读