Skip to content

Commit

Permalink
Refactor MongoConfigManager to use Promises for MongoDB connection ha…
Browse files Browse the repository at this point in the history
…ndling and improve error logging
  • Loading branch information
KillianG committed Nov 21, 2024
1 parent c0fbb85 commit 9b9db18
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions extensions/notification/configManager/MongoConfigManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,7 @@ class MongoConfigManager extends BaseConfigManager {
MongoClient.connect(mongoUrl, {
replicaSet: this._mongoConfig.replicaSet,
useNewUrlParser: true,
},
(err, client) => {
if (err) {
this._logger.error('Could not connect to MongoDB', {
method: 'MongoConfigManager._setupMongoClient',
error: err.message,
});
return cb(err);
}
}).then((client) => {

Check warning on line 103 in extensions/notification/configManager/MongoConfigManager.js

View workflow job for this annotation

GitHub Actions / tests

Unexpected parentheses around single function argument
this._logger.debug('Connected to MongoDB', {
method: 'MongoConfigManager._setupMongoClient',
});
Expand All @@ -133,6 +125,12 @@ class MongoConfigManager extends BaseConfigManager {
} catch (error) {
return cb(error);
}
}).catch(err => {
this._logger.error('Could not connect to MongoDB', {
method: 'MongoConfigManager._setupMongoClient',
error: err.message,
});
return cb(err);
});
}

Expand Down

0 comments on commit 9b9db18

Please sign in to comment.