jaredhanson/passport-http

Custom error code

diego-betto opened this issue · 4 comments

Hi,
any way to send custom error codes? Something like

passport.use(new BasicStrategy(
  function(userid, password, done) {
    User.findOne({ username: userid }, function (err, user) {
      if (err) { return done(err); }
      if (!user) { return done(null, false,401); }
      if (!user.verifyPassword(password)) { return done(null, false,403); }
      return done(null, user);
    });
  }
));

so for example

  • !user => 401
  • incorrect password => 403

Any clue?

Thank you

No. Both of those conditions should be a 401. Why do you want to change it?

Since the customer app needs these codes

Fail with an error, and respond with the status code in your error hander.

if (!user.verifyPassword(password)) {
  var err = new Error('Forbidden');
  err.status = 403;
  return done(err);
}

Nice works like a charm, changed a little bit since using Restify
error.status => error.statusCode

Thank you!