From 2103edb6044edc635e620a6c2ecb3d3ba33546c3 Mon Sep 17 00:00:00 2001 From: rmarops Date: Wed, 16 Nov 2022 22:21:15 -0500 Subject: [PATCH] moved client close out of finally block and fixed linting errors --- server/util-server.js | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/server/util-server.js b/server/util-server.js index 9b55864e9..ef15f7c3b 100644 --- a/server/util-server.js +++ b/server/util-server.js @@ -301,20 +301,23 @@ exports.postgresQuery = function (connectionString, query) { * @returns {Promise<(string[]|Object[]|Object)>} */ exports.mongodbPing = async function (connectionString) { - let client, db; - try { - client = await MongoClient.connect(connectionString, {useNewUrlParser: true}) - db = client.db(); - dbping = await db.command({ ping: 1 }); - if (dbping["ok"] === 1) { - return 'UP' - } - throw Error("failed"); - } - catch(err){ console.error(err); } - finally{ client.close(); } -} + let client; + try { + client = await MongoClient.connect(connectionString, { useNewUrlParser: true }); + let db = client.db(); + let dbping = await db.command({ ping: 1 }); + await client.close(); + if (dbping["ok"] === 1) { + return "UP"; + } else { + throw Error("failed"); + } + } catch (err) { + console.error(err); + throw Error(err) + } +}; /** * Query radius server