0

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.

0

1 Answer 1

1

The answer is no.

The above case will print:

About to call next("someError");
Handling err in main and err is:
someError

Note: I did more testing on this than I wrote in the above question, but I did not include it for the sake of brevity.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.