-
-
Notifications
You must be signed in to change notification settings - Fork 115
Open
Description
Inspired by expressjs/express#2896, but proposed here because as a breaking change it likely won't make it into Express 4.0 anyway, and Express 5.0 references this.
Instead of using the number of arguments to differentiate between error and normal handlers, is there any reason not to use named functions? Example:
route.get(function(req, res, next) {
next('oops')
}, function(err, req, res, next) {
res.end('Error')
})
Instead, we could say:
route.get(function(req, res, next) {
next('oops')
}, function error(err, req, res) {
res.end('Error')
})
And then just check for this.name
instead of fn.length
in layer.js:63.
Should work in all places where error handlers can be specified here and in express unless I'm overlooking something, and would remove the need (and warnings) for unused parameters.
Could even still allow the old style (but make it deprecated?) to not to break existing code.
Thoughts? :)