title: UnhandledPromiseRejectionWarning despite multiple Error checks
body: <p>I recently have been developing a web app with NODEJS. I have a db model that takes care of all crud operations. Sample DB model</p>
  
  <pre class="lang-js prettyprint-override"><code>    getDeviceList: function () {
          return new Promise(function (resolve, reject) {
              var sql = "SELECT * FROM `devices`";
              db.query(sql, function (err, result) {
                  if (err) {
                      console.log(`FAILED: ${err}`);
                      reject(err);
                  } else resolve(result);
              });
          });
      }
  </code></pre>
  
  <p>And I access this function in DB module like</p>
  
  <pre class="lang-js prettyprint-override"><code>router.get("/inventory/devices", checkAuth, function (req, res, next) {
      return new Promise(function (resolve, reject) {
          db.getDeviceList().then(function (result) {
              resolve(res.status(200).json(result));
          }).catch(function (err) {
              console.log(`FAILED: ${err}`);
              reject(res.status(200).json(err));
          });
      });
  });
  </code></pre>
  
  <p>Sometimes when I close the DataBase; I get <strong>UnhandledPromiseRejectionWarning</strong> but In my eyes I am handling all the promises. What is the best way of handling promises and is my method of <strong>retrun promise</strong> correct?
  My DB connection block is in <code>app.js</code></p>
  
  <pre class="lang-js prettyprint-override"><code>var connection = db.connectDB().then(function (connect) {}).catch(function (err) {
      console.log(`FAILED: ${err}`);
  });
  </code></pre>
  
  <p>and my <code>connectDB()</code> is </p>
  
  <pre class="lang-js prettyprint-override"><code>function () {
          return new Promise(function (resolve, reject) {
              db = mysql.createPool({
                  host: "localhost",
                  port: 3306,
                  user: "migration",
                  password: "iub5015",
                  database: "migration"
              });
              db.getConnection(function (err) {
                  if (err) {
                      console.log(`FAILED: ${err}`);
                      reject(err);
                  } else {
                      console.log("Connected");
                      resolve(db);
                  }
              });
          });
      }
  </code></pre>