How to handle PassportJS endpoint errors

Viewed 1675

If I visit the Facebook callback link at http://localhost/login?code=***

with a bogus code: FacebookTokenError: Invalid verification code format.
with the same code (replay attack): FacebookTokenError: This authorization code has been used.
with an expired code: FacebookTokenError: This authorization code has expired.

All of these errors are irrelevant to the client. I would like to simply retry the login process (redirect to Facebook again for authentication).

Express().get('/login', Passport().authenticate('facebook', {
    failureRedirect: '/',
}), function(req, res) {

});

However, upon error of those three described above, the server simply throws an error and emits to the client.

Is there an error callback for endpoint errors available?

1 Answers
Related