Skip to content

Use named functions for error handlers #50

Description

@CanisLupusXenonis

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? :)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions