问题描述
我已经使用名为return_match_uid
的node.js导出了一个函数。我将函数导入另一个快速路由文件中,并使用async
和await
的{{1}} try
处理错误。但是无论如何,即使我对Firestore doc建议的实时侦听器使用错误处理,catch
产生的错误也总是会滑倒并无法处理。
功能如下:
return_match_uid
exports.return_match_uid = function return_match_uid() {
return new Promise((resolve,reject) => {
const unsub = db.collection('cities').onSnapshot(() => {
throw ("matching algo error");
resolve();
unsub();
},err => {
console.log(err);
})
})
})
我在函数内部抛出的错误:const Router = require('express').Router;
const router = new Router();
const {return_match_uid} = require("./match_algo");
router.get('/match',async (req,res) => {
try {
var match_user = await return_match_uid(req.query.data,req.query.rejected);
res.send(match_user);
}
catch (error) {
console.log("Matching algorithm return error: " + error);
}
})
不会被函数中的matching algo error
或路由器中的err => {console.log(err);})
try
块捕获。它滑倒并导致我的应用崩溃。它显示以下错误:
catch
我在 throw "matching algo error!";
^
matching algo error!
(Use `node --trace-uncaught ...` to show where the exception was thrown)
[nodemon] app crashed - waiting for file changes before starting...
中抛出错误,因为其中还有其他一些代码,并且有可能产生错误。如果可以,我想确保它得到正确处理。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)