我不知道为什么会出现这种错误。我在互联网上搜索所有可能的解决方案仍然没有找到任何解决方案。这是我的API调用节点函数。
exports.GetEmployeeConfirmationList = function (req, res) {
var request = dbConn.request();
request.execute(storedProcedures.GetEmployeeConfirmationList).then(function (response) {
res.status(200).send({
success: true,
data: response.recordset
});
}).catch(function (err) {
res.status(200).send({
success: false,
message: err.message
});
});
};
如何克服这个问题? 提前谢谢。
答案 0 :(得分:2)
修改代码以使用箭头功能,因为res
对象正在失去其范围。
调用GetEmployeeConfirmationList
回调时,它不知道res
对象因此undefined
。因此,在执行res.status
时,它会抛出异常并进入catch
块,再次执行res.status
并再次中断并导致未处理的承诺拒绝。
您可以在err
块中捕获log
对象和finally
对象,以检查它是否正在发生。
exports.GetEmployeeConfirmationList = function (req, res) {
var request = dbConn.request();
request.execute(storedProcedures.GetEmployeeConfirmationList).then((response) => {
res.status(200).send({
success: true,
data: response.recordset
});
}).catch((err) => {
res.status(200).send({
success: false,
message: err.message
});
});
};