From 712a3c29d48521ef7148807bdc1e69674339a4be Mon Sep 17 00:00:00 2001 From: Louis Lam Date: Sat, 14 Jan 2023 21:06:10 +0800 Subject: [PATCH] Fix Postgres monitor do not handle some error cases correctly --- server/util-server.js | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/server/util-server.js b/server/util-server.js index 60d8baac7..f66b10399 100644 --- a/server/util-server.js +++ b/server/util-server.js @@ -280,18 +280,23 @@ exports.postgresQuery = function (connectionString, query) { const client = new Client({ connectionString }); - client.connect(); - - return client.query(query) - .then(res => { - resolve(res); - }) - .catch(err => { + client.connect((err) => { + if (err) { reject(err); - }) - .finally(() => { client.end(); - }); + } else { + // Connected here + client.query(query, (err, res) => { + if (err) { + reject(err); + } else { + resolve(res); + } + client.end(); + }); + } + }); + }); };