title: Express 4 middleware when route is not found (finalhandler not called): how to check for it?
body: <p>I set up the following Express 4 middleware stack:</p>
  
  <pre><code>const app = express();
  const router = express.Router();
  router.get('/test', testResponse);
  app.use(checkAccessToken);
  app.use(router);
  app.use(sendResponse);
  //Error Handling
  app.use(function(err,req,res,next) {
    // ... Do something here
  });
  
  function sendResponse(req, res) {
    res.json({
      data: res.locals.data,
      meta: res.locals.meta
    });
  }
  </code></pre>
  
  <p>If I call the server with a route that doesn't exist (like GET /something) the function sendResponse just after the router handler is called and the caller gets a standard response instead of the usual message "Cannot GET /something", coming from the finalhandler module.<br>
  I thought instead that the error handler should have been called, but this is not the case.<br>
  Is there a way to force the router to emit an error if a route is not found or to check in the standard response handler if a route has not been matched?<br>
  I know that I can add a value in res.locals for any route that has a match and check for it in the standard response handler, but I'd like to use the "right" way to do it, rather than using a workaround.</p>