Improved error msg handling
| | |
| | | const pgconn = new Pool({ |
| | | connectionString: DB_CONFIG, |
| | | ssl: false, |
| | | }) |
| | | }); |
| | | |
| | | module.exports = { pgconn } |
| | |
| | | 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' }); |
| | | } |
| | | }) |
| | | }); |
| | | |
| | |
| | | h1= title |
| | | hr |
| | | br |
| | | if error |
| | | .alert.alert-danger #{error} |
| | | else |
| | | table.table.table-striped.table-bordered.table-hover |
| | | if contacts |
| | | thead |