From 1c9e90c1619d56f199c119874d09263acd827b07 Mon Sep 17 00:00:00 2001 From: James Barnett Date: Sun, 25 Feb 2018 13:31:00 +0000 Subject: Report connection errors. Add test connection functionality --- query-executor.js | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'query-executor.js') diff --git a/query-executor.js b/query-executor.js index 88df7e1..ee7552b 100644 --- a/query-executor.js +++ b/query-executor.js @@ -3,6 +3,8 @@ const { remote, ipcRenderer } = require("electron"); const { Pool } = require("pg"); +const connectionTestQuery = "SELECT now()"; + const executorId = require("uuid/v1")(); const connectionConfig = remote.getCurrentWindow().connectionConfig; @@ -15,8 +17,19 @@ const connectionPool = new Pool({ port: connectionConfig.port }); -// Initialisation completed -ipcRenderer.send("queryExecutor.initialiseConnectionCallback", executorId); +// Test the newly initialised connection +connectionPool.query(connectionTestQuery, (err, res) => { + setErrorCauseIfExists(err); + ipcRenderer.send("queryExecutor.initialiseConnectionCallback", {error: err, executorId: executorId}); +}); + +function setErrorCauseIfExists(error) { + if (error !== undefined) { + // The IPC payload is serialised to JSON before transmission, so the prototype chain is lost. + // So store the nicely formatted error message as a property. + error.cause = error.toString(); + } +} ipcRenderer.on("queryExecutor.runQuery", (event, payload) => { @@ -25,11 +38,7 @@ ipcRenderer.on("queryExecutor.runQuery", (event, payload) => { console.log(err, res); - if(err !== undefined) { - // The IPC payload is serialised to JSON beofre transmisison, so the protoype chain is lost. - // So store the nicely formatted error message as a property. - err.cause = err.toString(); - } + setErrorCauseIfExists(err); ipcRenderer.send("queryExecutor.runQueryComplete", { "error": err, -- cgit v1.2.3