[英]Catch and trace middleware exceptions (less-middleware) in Express 3.0
First of all, I tried to follow this question (but adapted to Express 3.0): 首先,我试图遵循这个问题(但适用于Express 3.0):
Nodejs: How to catch an exception from middleware? Nodejs:如何从中间件中捕获异常?
app.use(function(err, req, res, next) {
console.error('Middleware exception:' + err.stack);
next(err);
});
However, no matter where I put it in my middleware chain, before or after app.use(lessMiddleware);
但是,无论我把它放在我的中间件链中,
app.use(lessMiddleware);
之前或之后app.use(lessMiddleware);
(from require('less-middleware')
) I still get: (来自
require('less-middleware')
)我仍然得到:
GET /? 304 44ms
source : <my path>/style.less
dest : <my path>/style.css
read : <my path>/style.less
DEBUG:
DEBUG: <my path>/node_modules/less-middleware/node_modules/less/lib/less/parser.js:385
throw new(LessError)(e, env);
^
DEBUG: [object Object]
DEBUG: Program node app.js exited with code 1
Kind readers, how to solve this problem? 善良的读者,如何解决这个问题? I want to:
我想要:
To my surprise the problem was in less-middleware. 令我惊讶的是,问题在于中间件较少。 I kind of expected it to be a more mature solution.
我有点期待它成为一个更成熟的解决方案。 I fixed it and made a pull request on Github .
我修复了它并在Github上发出了拉取请求 。 Hope this helps anybody encountering the same problem.
希望这可以帮助任何人遇到同样的问题。 Cheers.
干杯。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.