Custom error code
diego-betto opened this issue · 4 comments
diego-betto commented
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
jaredhanson commented
No. Both of those conditions should be a 401
. Why do you want to change it?
diego-betto commented
Since the customer app needs these codes
jaredhanson commented
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);
}
diego-betto commented
Nice works like a charm, changed a little bit since using Restify
error.status => error.statusCode
Thank you!