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.
This commit is contained in:
Angel98518 2026-01-20 06:47:51 +01:00
parent 7f94ac29f4
commit 472b1c4001

View File

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