Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/475.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
异步-等待JavaScript:无法从错误对象捕获错误详细信息_Javascript_Node.js_Express_Async Await_Try Catch - Fatal编程技术网

异步-等待JavaScript:无法从错误对象捕获错误详细信息

异步-等待JavaScript:无法从错误对象捕获错误详细信息,javascript,node.js,express,async-await,try-catch,Javascript,Node.js,Express,Async Await,Try Catch,在我的Node Express JS web app中,我有以下函数链,其中后续api函数尝试调用服务函数并捕获服务函数抛出的错误 在FWBDataExtracService.js const FWBDataExtracService = { getFWBData: async () => { ... ... // Check if .tabledata exists; If not, throw an error to be caught in t

在我的Node Express JS web app中,我有以下函数链,其中后续api函数尝试调用服务函数并捕获服务函数抛出的错误

FWBDataExtracService.js

const FWBDataExtracService = {
    getFWBData: async () => {
        ... ...
        // Check if .tabledata exists; If not, throw an error to be caught in the calling function.
        if ($('.tabledata1').length == 0) {
            console.error("DOM element .tabledata not found on the page.");
            throw new Error("DOM element .tabledata not found on the page.");
        }
        ... ...
    }
}
api.js
中,路由器函数试图调用FWBDataExtracService.getFWBData函数,然后捕获错误

const FWBDataExtracService = require('../services/FWBDataExtracService')
router.get('/GetDataFromFWB', async (req, res, next) => {
    try {
        .... ....
        // ### THIS WILL FAIL AND AN ERROR WILL BE THROWN
        const FWBJson = await FWBDataExtracService.getFWBData();
        .... ....
    } catch(err) {
        // ### ERR IS ALWAYS EMPTY
        console.log("*", JSON.stringify(err));
        return res.send({'Error': JSON.stringify(err)});
    }
})

由于模拟了错误,我希望捕获错误并打印错误消息。但是
err
始终为空。

未指定错误属性的精确位置。在某些环境中,它位于错误对象本身上——在某些环境中,它位于原型上,或者是一个getter,或者类似的东西

JSON.stringify
将只迭代可枚举的自身属性。在Chrome中,
.message
属性是不可枚举的,因此在字符串化时不包括它:

const e=新错误('foo');

log(Object.getOwnPropertyDescriptor(e,“message”)尝试显示
错误堆栈
显示的内容?