From 472b1c400115124e9531833384c687dae7fcc7ee Mon Sep 17 00:00:00 2001 From: Angel98518 Date: Tue, 20 Jan 2026 06:47:51 +0100 Subject: [PATCH] fix: MongoDB monitor JSON.parse error handling Add proper error handling for invalid JSON in databaseQuery field. Previously, invalid JSON would cause an unhandled error. Now it provides a clear error message to the user. --- server/monitor-types/mongodb.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/server/monitor-types/mongodb.js b/server/monitor-types/mongodb.js index bbe217c64..cf2ca4ca3 100644 --- a/server/monitor-types/mongodb.js +++ b/server/monitor-types/mongodb.js @@ -12,7 +12,11 @@ class MongodbMonitorType extends MonitorType { async check(monitor, heartbeat, _server) { let command = { ping: 1 }; if (monitor.databaseQuery) { - command = JSON.parse(monitor.databaseQuery); + try { + command = JSON.parse(monitor.databaseQuery); + } catch (error) { + throw new Error(`Invalid JSON in database query: ${error.message}`); + } } let result = await this.runMongodbCommand(monitor.databaseConnectionString, command);