title: How to handle errors with Express-JWT
body: <p>I am trying to incorporate the express-jwt library and I do not quite understand how it's error handling works.</p>
  <p>The <a href="https://github.com/auth0/express-jwt" rel="noreferrer">documentation</a> says:</p>
  <blockquote>
  <p>Error handling</p>
  <p>The default behavior is to throw an error when the token is invalid, so you can &gt;add your custom logic to manage unauthorized access as follows:</p>
  </blockquote>
  <pre><code>    app.use(function (err, req, res, next) {
        if (err.name === 'UnauthorizedError') {
          res.status(401).send('invalid token...');
        }
      });
  </code></pre>
  <p>But I am confused how that works. If I have a simple <code>req</code> <code>res</code> situation, and I want to call <code>next</code> if the token is valid, or call <code>next</code> with an error if it is not, where to I put that <code>app.use</code> function?</p>
  <p>For instance, here is my code:</p>
  <pre><code>router.post('/', expressJwt({  
    secret: jwtSecret,     
    credentialsRequired: false  
  }), (req, res, next) =&gt; {   
    databaseController.findUser(req.user.email, (err, user) =&gt; {          
      if (err) {          
        return next(err)      
      }                        
      res.json(user)     
    })         
  })
  </code></pre>
  <p>The <code>err</code> here would come from my DB call, not from the express-jwt validation.
  Any help is appreciated.</p>