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:
parent
7f94ac29f4
commit
472b1c4001
@ -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);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user