Ravi Srinivasan
2019-09-12 6b13d515c8a240b3c506166d27574d2917115d8b
Improved error msg handling
3 files modified
12 ■■■■ changed files
contacts/db/config.js 2 ●●● patch | view | raw | blame | history
contacts/routes/index.js 7 ●●●● patch | view | raw | blame | history
contacts/views/index.pug 3 ●●●●● patch | view | raw | blame | history
contacts/db/config.js
@@ -5,6 +5,6 @@
const pgconn = new Pool({
    connectionString: DB_CONFIG,
    ssl: false,
})
});
  
module.exports = { pgconn }
contacts/routes/index.js
@@ -6,11 +6,14 @@
router.get('/', function(req, res) {
  pgconn.query('SELECT * FROM contacts', function(err,results) {
    if (err) {
      throw err
      console.log(err);
      res.render('index', { error: 'Database connection failure! '+err.stack, contacts: null, title: 'Contact List' });
    }
    else {
    let contacts = results.rows;
    console.log(contacts);
    res.render('index', { contacts: contacts, title: 'Contact List' });
      res.render('index', { error: null, contacts: contacts, title: 'Contact List' });
    }
  })
});
contacts/views/index.pug
@@ -6,6 +6,9 @@
      h1= title
      hr
      br
      if error
        .alert.alert-danger #{error}
      else
      table.table.table-striped.table-bordered.table-hover
        if contacts
          thead