Friday, 15 July 2011

javascript - Pass err into express.js Router, Node.js -


What could be lost in an Express. Js router?

There is no answer in express.js documentation related to expressing middleware, routers, and error handling (I can not post links due to lack of reputation).

I searched StackOverflow well and could not find an answer.

I searched very well, and could not find the answer.

Example:

app.js

  var express = required ('Express'); Var myRouter = Required ('./ myRouter.js'); Var app = express (); App.use (function (req, res, next) {console.log (about next call ("some error"); next ('some error');}); app use (micrower); app. Use (console, error, res, next) {console.log ('main error and error handling error:'); 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 ('airer');});  

I did all my versions with version 4.12.2 express.

answer no The above case will be printed:

  About calling forward ("someError"); The main and error is to handle the errors: someError  

Note: I wrote in the above question, instead I did a lot of testing on it, but I did not include it for the sake of recap.


No comments:

Post a Comment