title: How to Handle Unhandled promise rejection in async object method in Node.js expressjs?
body: <p>Im using the async function inside the object to send a response in express.js</p>
  
  <p>Controller Code :</p>
  
  <pre><code>module.exports = {
  
      async signUpEmail(req, res) {
  
          /**
           * @description Parameters from body
           * @param {string} firstName - First Name
           * @inner
           */  
  
          const firstName = req.body.firstName;
  
          res.send({ success: name });
          throw new Error(); // purposely Done
      }
  }
  </code></pre>
  
  <p><strong>Question:</strong></p>
  
  <p>Since the signUpEmail method is async in my case and it will get rejected with whatever my async method throw's here it's comes <code>Error</code>.(purposely put there)</p>
  
  <p>so getting this logged in the console.</p>
  
  <pre><code>(node:13537) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error
  (node:13537) DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
  </code></pre>
  
  <p>So i'm supposed to handle it from the routes from where i'm calling it.</p>
  
  <p>Router Code</p>
  
  <pre><code>    const routes = require('express').Router();
  const SignUpController = require('../controllers/signUpController')
  
  // /signup
  routes.post('/', SignUpController.signUpEmail);
  
  module.exports = routes;
  </code></pre>
  
  <p>some what like this <code>SignUpController.signUpEmail().then(…);</code> But since i'm not calling function in the routes i'm just passing. <strong>How this can be done effectively</strong> ?</p>
  
  <p>PS:Please Don't suggest too complicated solutions. I'm beginner with JS and is learning through.</p>
  
  <p>I Didn't use chainable route handlers because i want to create modular, mountable route handler.</p>
  
  <p><a href="http://expressjs.com/en/guide/routing.html#express.Router" rel="noreferrer">Official Doc Example</a></p>