[英]Pass err into express.js Router, Node.js
可以将err传递到express.js路由器吗?
在express.js文档中,与快速中间件,路由器和错误处理有关的问题没有答案(由于缺乏声誉,我无法发布链接)。
我彻底搜索了StackOverflow,却找不到答案。
我在google上进行了彻底的搜索,找不到答案。
例:
app.js
var express = require('express');
var myRouter = require('./myRouter.js');
var app = express();
app.use(function(req, res, next){
console.log('About to call next("someError")';
next('someError');
});
app.use(myRouter);
app.use(function (err, req, res, next){
console.log('Handling error in main and err is:');
console.log(err);
});
myRouter.js
var express = require('express');
var myRtr = module.exports = express.Router();
myRtr.use(function(err, req, res, next){
console.log('Handling error in myRouter.js');
next('anotherError');
});
我使用Express 4.12.2进行了所有测试。
答案是不。
上面的情况将打印:
About to call next("someError");
Handling err in main and err is:
someError
注意:比起上面的问题,我对此进行了更多的测试,但是为了简洁起见,我没有将其包括在内。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.