Fix Postgres monitor do not handle some error cases correctly

This commit is contained in:
Louis Lam 2023-01-14 21:06:10 +08:00
parent e9497ac1ab
commit 712a3c29d4

View File

@ -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();
});
}
});
});
};