Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/39.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
如何在Express JS服务器日志中查看堆栈跟踪?_Express_Vue.js_Axios_Nuxt.js - Fatal编程技术网

如何在Express JS服务器日志中查看堆栈跟踪?

如何在Express JS服务器日志中查看堆栈跟踪?,express,vue.js,axios,nuxt.js,Express,Vue.js,Axios,Nuxt.js,我的堆栈包括:Nuxt(Vue)、Express.js、Axios 当我进行一个失败的REST调用时,如下所示: axios.get('api/data-test'); 我在客户机中看到了这一点: xhr.js:172 GET http://localhost:3000/api/data-test 500 (ReferenceError) dispatchXhrRequest @ xhr.js:172 xhrAdapter @ xhr.js:11 dispatchRequest @ dispa

我的堆栈包括:Nuxt(Vue)、Express.js、Axios

当我进行一个失败的REST调用时,如下所示:

axios.get('api/data-test');
我在客户机中看到了这一点:

xhr.js:172 GET http://localhost:3000/api/data-test 500 (ReferenceError)
dispatchXhrRequest @ xhr.js:172
xhrAdapter @ xhr.js:11
dispatchRequest @ dispatchRequest.js:59
Promise.then (async)
request @ Axios.js:53
Axios.<computed> @ Axios.js:68
wrap @ bind.js:9
getDataFromDb @ test.vue:21
invokeWithErrorHandling @ vue.runtime.esm.js:1854
invoker @ vue.runtime.esm.js:2179
original._wrapper @ vue.runtime.esm.js:6911
createError.js:16 Uncaught (in promise) Error: Request failed with status code 500
    at createError (createError.js:16)
    at settle (settle.js:17)
    at XMLHttpRequest.handleLoad (xhr.js:59)
xhr.js:172获取http://localhost:3000/api/data-测试500(参考错误)
dispatchxhrequest@xhr.js:172
xhrAdapter@xhr.js:11
dispatchRequest@dispatchRequest.js:59
Promise.then(异步)
request@Axios.js:53
Axios@Axios.js:68
包装@bind.js:9
getDataFromDb@test.vue:21
invokeWithErrorHandling@vue.runtime.esm.js:1854
invoker@vue.runtime.esm.js:2179
原始._wrapper@vue.runtime.esm.js:6911
createError.js:16未捕获(承诺中)错误:请求失败,状态代码为500
在createError(createError.js:16)
结算时(结算js:17)
在XMLHttpRequest.handleLoad(xhr.js:59)
很明显有些东西已经变成梨形了,但是服务器是沉默的


如何查看服务器上出现错误的堆栈跟踪?

请查看Express错误处理文档:

它解释了如何处理同步和异步错误。 基本上,您需要将错误作为next()函数的参数传递,并提供个性化的错误处理程序或使用默认的错误处理程序:

app.use(function(err, req, res, next) {
  console.error(err.stack);
  res.status(500).send('Internal Server Error');
});

此代码必须放在所有其他“使用”调用之后。

请查看快速错误处理文档:

它解释了如何处理同步和异步错误。 基本上,您需要将错误作为next()函数的参数传递,并提供个性化的错误处理程序或使用默认的错误处理程序:

app.use(function(err, req, res, next) {
  console.error(err.stack);
  res.status(500).send('Internal Server Error');
});

此代码必须放在所有其他调用“use”之后。

好的,这确实有效。当然,在所有其他调用“use”之后,这段代码需要位于一个非常特定的位置。为什么打印堆栈跟踪不仅仅是默认行为,我相信我永远也不会知道。好吧,这确实奏效了。当然,在所有其他调用“use”之后,这段代码需要位于一个非常特定的位置。为什么打印堆栈跟踪不仅仅是默认行为,我相信我永远不会知道。