title: How to redirect after error inside of PassportJS/Express?
body: <p>When configuring passport using Express and NodeJS, I am throwing an error if the user has an invalid email address. After this error I would like to redirect to a failure page giving them instructions on how to log in correctly. Is there are a better way to do this? If not, how would I go about catching the error in some fashion and redirecting to a new page.</p>
  
  <pre><code>passport.use(new GoogleStrategy({
          clientID     : auth.googleAuth.clientID,
          /* Settings redacted for brevity */
      },
      function(token, refreshToken, profile, done) {
          User.findOne(
              {
                  "google.id" : profile.id
              },
              function(err, user) {
  
                  if (err) return done(err)
  
                  if (user) return done(null, user)
  
                  else {
  
                      if (email.indexOf("lsmsa.edu") &gt; -1) {
  
                          // Code redacted for brevity
  
                      } else {
                          done(new Error("Invalid email address"))
                      }
                  }
              }
          )
      }))
  </code></pre>