bnoguchi/everyauth — Issue #166: Error from registerLocals not handled
Author: chrisleishman
Created: 2012-01-29 02:03:03+00:00
State: open

I'm trying to do an "invite-only" registration, by providing unique access keys for the registration process. I've configured everyauth using the following:

```javascript
everyauth.password
.getRegisterPath('/register/:id')
.registerLocals(function(req, res, done) {
var id = req.param('id');
if (!id)
return done(new Error('missing id'));
User.findOne({access_key: id}, function(err, user) {
if (err)
return done(err);
if (!user)
return done(new Error('Unknown id'));
done(null, {user: user});
});
})
```

This works fine, except in the error cases. Currently these throw an uncaught exception to be thrown, which crashes the express application. It also cannot be caught using the express "app.error()" handler.

This seems to be a bug, as an error should be able to be handled in some manner. However, it would be even better if it was possible to decline to handle the route, resulting in a 404, in exactly the same way the normal handlers decline by calling "next()".

Any thoughts, fixes or other assistance would be greatly appreciated.

Chris