title: NodeJS: Unhandled promise rejection
body: <p>I'm having a little problem and after debugged all the app I noticed that this is the file that's causing the problem, returning me a <code>UnhandledPromiseRejection</code> </p>
  
  <pre><code>'use strict'
  
  const connection = require('../models/'),
        oracledb   = require('oracledb'),
        conexion   = oracledb.getConnection(connection)
  oracledb.outFormat = oracledb.OBJECT;
  
  module.exports  = {
    index(req, res) {
    conexion.then(con =&gt; {
      return con.execute(
        `SELECT id_application, name, description, creation_date ` +
        `FROM application `
      ).then(bucket =&gt; {
        return con.execute(
          `SELECT id_definition, id_application, field_name_original, field_name_new,
          column_name, position, id_type_data, field_size, creation_date,
          description, filter, visible ` +
          `FROM definition `
        ).then(definitions =&gt; {
          res.status(200).json(creaJSON(bucket, definitions))
        }).catch(error  =&gt; { return res.status(500).json({'message': error}) })
      }).catch(err  =&gt;  { return res.status(500).json({'message': err}) })
    }).catch(err  =&gt;  { return res.status(500).json({'message': err}) })
    },
    create(req, res)  {
    },
    update(req, res)  {
    }
  }
  
  const doRelease = (connection) =&gt; {
    connection.close((err)  =&gt;  {
      if(err) console.error(err.message);
    })
  }
  
  const creaJSON = (buckets, definitions)  =&gt; {
    var df = new Array()
    buckets['rows'].map(obj =&gt;  {
      definitions['rows'].map(def =&gt;  {
        if(obj['ID_APPLICATION'] == def['ID_APPLICATION']) df.push(def)
      })
      obj['Definitions'] = df
      df = []
    })
    return buckets.rows
  }
  </code></pre>
  
  <p>after the <code>UnhandledPromiseRejection</code> is being followed by: <code>Error: ORA-12170: TNS:Connect timeout occurred</code> </p>
  
  <pre><code>(node:1270) 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>I already looked for solutions, some says that promises are not catching correctly but I don't see any problem with them. Any other suggestion?</p>
  
  <p>Any help will be welcome.</p>
  
  <p>Thanks</p>