【发布时间】:2019-09-11 13:14:36
【问题描述】:
我有一个简单的loopback.js 应用程序,其中包含strong-error-handler https://github.com/strongloop/strong-error-handler 和middlewares/middleware.json 中的以下代码
"final:after": {
"./middlewares/log-error": {},
"strong-error-handler": {
"params": {
"debug": false,
"log": true
}
}
}
我的middlewares/log-error 文件如下所示
module.exports = function createErrorLogger(options) {
return function logError(err, req, res, next) {
// your custom error-logging logic goes here
console.log("inside custom error logging");
const status = err.status || err.statusCode;
if (status >= 500) {
// log only Internal Server errors
console.log('Unhandled error for request %s %s: %s',
req.method, req.url, err.stack || err);
}
// Let the next error handler middleware
// produce the HTTP response
next(err);
};
}
我有一个像这样的简单函数
function myfunc(){
myvar.asdf #myvar is undefined
}
在上述函数中myvar 是未定义的。所以当我调用这个函数时
http://localhost:3001/myfunc 它抛出这个错误并且应用程序崩溃
我想避免应用崩溃。一个简单的try/catch 有助于避免这个错误,但是有没有办法避免发生这种错误时节点崩溃?
【问题讨论】:
标签: node.js loopbackjs strongloop