From a3bd7fa779d0b37c04b0a6553ed02f59a2d00b63 Mon Sep 17 00:00:00 2001 From: Andris Reinman Date: Tue, 26 Apr 2016 15:46:29 +0300 Subject: [PATCH] Show meaningful MySQL errors when startup fails --- index.js | 2 +- lib/dbcheck.js | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index d3e1e036..565119fa 100644 --- a/index.js +++ b/index.js @@ -34,7 +34,7 @@ let server = http.createServer(app); // Check if database needs upgrading before starting the server dbcheck(err => { if (err) { - log.error('DB', err); + log.error('DB', err.message || err); return process.exit(1); } /** diff --git a/lib/dbcheck.js b/lib/dbcheck.js index 45d2be66..30b13b0c 100644 --- a/lib/dbcheck.js +++ b/lib/dbcheck.js @@ -21,6 +21,12 @@ let db = mysql.createPool(mysqlConfig); function listTables(callback) { db.getConnection((err, connection) => { if (err) { + if(err.code === 'ER_ACCESS_DENIED_ERROR'){ + err = new Error('Could not access the database. Check MySQL config and authentication credentials'); + } + if(err.code === 'ECONNREFUSED' || err.code === 'PROTOCOL_SEQUENCE_TIMEOUT'){ + err = new Error('Could not connect to the database. Check MySQL host and port configuration'); + } return callback(err); } let query = 'SHOW TABLES';