-
-
Notifications
You must be signed in to change notification settings - Fork 19.7k
Open
Labels
Description
var webapps = express.Router();
module.exports = webapps;
function handleError(err, req, res, next) {
//this function is not executed
res.send("hello");
next();
}
webapps.param("app", function(req, res, next, name) {
next("asfaf");
});
webapps.route("/:app")
.all(handleError);
I am expected handleError to be executed and send a response of "hello", but instead "asfaf" is being send with status 500.
Metadata
Metadata
Assignees
Labels
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
dougwilson commentedon Jan 1, 2015
Ah, it's because the error handler is within the route and since the error is the parameter, the route is not actually entered.
I agree though, that it would make sense to execute error handlers within the route if there was an error in a parameter for the route.
cosmosgenius commentedon Jan 1, 2015
So if we have to catch this type of error it has to be on top of the router?
dougwilson commentedon Jan 1, 2015
Yes, it has to be on the router, after your route. You can also add a second route with the same path that does not use the same parameter to try and only capture the correct error.
This change would be a pretty big behavior change, so it'll likely have to wait for 5.0, which is due this month sometime after the io.js release.
dougwilson commentedon Jan 1, 2015
I'll put this in the router module though, so you can use that in any version of express, so you don't have to wait.
scottcorgan commentedon Jan 14, 2015
So does this remove the error middleware with 4 params?
dougwilson commentedon Jan 14, 2015
No. This is to make it possible to catch errors from
app.param(name, fn)
functions within the route itself.