title: How to use express.Router instance for error handling
body: <p>According to the <a href="https://expressjs.com/en/4x/api.html#app.use" rel="nofollow noreferrer">documentation</a>, any nodejs express middleware function can be replaced by App or Router instances:</p>
  
  <blockquote>
    <p>Since router and app implement the middleware interface, you can use
    them as you would any other middleware function.</p>
  </blockquote>
  
  <p>This is some generic error handling I use:</p>
  
  <pre><code>express()
      .use('/test', new TestRouter())
      .use((err, req, res, next) =&gt; {
          console.error(err.stack);
          res.status(500).send(err.message);
      })
      .listen(PORT);
  </code></pre>
  
  <p>I tried to replace my error handling with an error-handling Router, but now the callback is never executed and express uses it's default error handling.</p>
  
  <pre><code>const handler = new express.Router();
  handler.use((err, req, res, next) =&gt; {
      console.error(err.stack);
      res.status(500).send(err.message);
  });
  
  express()
      .use('/test', new TestRouter())
      .use(handler)
      .listen(PORT);
  </code></pre>
  
  <p>Why is this not working as expected and how could I solve it?</p>