Skip to content

Specify error type when throwing an error #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

rafis
Copy link

@rafis rafis commented Dec 11, 2015

Sometimes you need to know which error were thrown, for example,

router.post('/register', function(req, res, next) {
    User.register(User.build({username: username}), req.body.password, function(err) {
        if (err) {
            // Handle specific errors customly
            if ('MissingUsernameError' == err.name || 'UserExistsError' == err.name) {
                res.status(400);
                res.render('auth/register', { errorMsg: err.message});
                return;
            }
            // System error (fatal error)
            return next(err);
        }
        ...
   });
});

It would be nice to specify that error type. Also maybe it would be better to specify each error in separate js file in errors subfolder like https://github.com/jaredhanson/passport/blob/master/lib/errors/authenticationerror.js .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant