title: Custom Error message using passport Bearer
body: <p>I'm using passport to secure my API.
  I kind of struggle to understand how i'm supposed to send back custom message in case of error and i'm hoping to find an answer here.</p>
  
  <p>Here is what i did:</p>
  
  <p>A route (server.js): </p>
  
  <pre><code>router.route('/Applications').get(authController.BearerAuthenticated, applicationController.getApplications);
  </code></pre>
  
  <p>My Passport Stuff (authController.js):</p>
  
  <pre><code>Passport.use(new BearerStrategy(function(token, cb) {
  Token.findOne({token: token}, function(err, token){ 
      if (err){return cb(null, false);}
      if (!token) { return cb(null, false); }
      return cb(null, token);
  });
  }));
  
  exports.BearerAuthenticated = Passport.authenticate('bearer', {session: false});
  </code></pre>
  
  <p>My Application method (Application.js)</p>
  
  <pre><code>exports.getApplications = function(req, res) {
  Application.find({userId:req.user._id}, function(err, apps) {
  if (err)
    res.send(err);
  res.json(apps);
  });
  };
  </code></pre>
  
  <p>If my token is valid and the Bearer method return</p>
  
  <pre><code>return cb(null, token);
  </code></pre>
  
  <p>Then i can enter my getApplications method. It makes sense.</p>
  
  <p>The thing is when the token is not valid, i don't enter the method (makes sense too) but i can't figure out a way to return a custom message to the client instead of the following message i get by default.</p>
  
  <pre><code>Unauthorized
  </code></pre>
  
  <p>What would be a way to return a Json with an error code to properly let the user know that his token is dead or simply does not exist ?</p>
  
  <p>Thanks for you time. :)</p>