Can an err be passed into an express.js Router?
There is no answer to this in the express.js documentation related to express middleware, routers, and error handling (I can't post links due to lack of reputation).
I thoroughly searched StackOverflow and couldn't find an answer.
I google searched pretty thoroughly, and couldn't find the answer.
Example:
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');
});
I did all my testing with express version 4.12.2.