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' }); |
| | | } |
| | | let contacts = results.rows; |
| | | console.log(contacts); |
| | | res.render('index', { contacts: contacts, title: 'Contact List' }); |
| | | else { |
| | | let contacts = results.rows; |
| | | console.log(contacts); |
| | | res.render('index', { error: null, contacts: contacts, title: 'Contact List' }); |
| | | } |
| | | }) |
| | | }); |
| | | |
| | |
| | | h1= title |
| | | hr |
| | | br |
| | | table.table.table-striped.table-bordered.table-hover |
| | | if contacts |
| | | thead |
| | | tr |
| | | th ID |
| | | th First Name |
| | | th Last Name |
| | | th EMail |
| | | tbody |
| | | for contact in contacts |
| | | if error |
| | | .alert.alert-danger #{error} |
| | | else |
| | | table.table.table-striped.table-bordered.table-hover |
| | | if contacts |
| | | thead |
| | | tr |
| | | td= contact.id |
| | | td= contact.firstname |
| | | td= contact.lastname |
| | | td= contact.email |
| | | else |
| | | tr |
| | | td |
| | | | No contacts found |
| | | th ID |
| | | th First Name |
| | | th Last Name |
| | | th EMail |
| | | tbody |
| | | for contact in contacts |
| | | tr |
| | | td= contact.id |
| | | td= contact.firstname |
| | | td= contact.lastname |
| | | td= contact.email |
| | | else |
| | | tr |
| | | td |
| | | | No contacts found |