title: Unhandled rejections in Express applications
body: <p>I have a lot of ES6 promise based code running inside my express app. If there is an error that is never caught I'm using the following code to deal with it:</p>
  
  <pre><code>process.on('unhandledRejection', function(reason, p) {
    console.log("Unhandled Rejection:", reason.stack);
    process.exit(1);
  });
  </code></pre>
  
  <p>This works fine for debugging purposes. </p>
  
  <p>In production however I would like to trigger the 500 error handler, to show the user the standard "Something went wrong" page. I have this catch all error handler that currently works for other exceptions:</p>
  
  <pre><code>app.use(function(error, req, res, next) {
    res.status(500);
    res.render('500');
  });
  </code></pre>
  
  <p>Putting the unhandledRejection inside a middleware does not work as it's async and offen results in a <code>Error: Can't render headers after they are sent to the client.</code></p>
  
  <p>How would I go about rendering the 500 page on an <code>unhandledRejection</code>?</p>