Skip to content

Commit 8969f73

Browse files
committed
Emit close event for closed connections
1 parent 5c2ffd7 commit 8969f73

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
lines changed

lib/fhmongodb.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,13 +153,20 @@ Database.prototype.tearUp = function (auth) {
153153
if (interval) {
154154
clearInterval(interval);
155155
}
156-
self.db = db.db(self.name);
157-
authenticateUser(auth);
158156

159-
self.db.on('error', function (err) {
160-
console.warn("mongodb emits error: " + err);
157+
db.on('error', function (err) {
158+
console.warn('Mongo connection error:' + err);
161159
self.emit('error', err);
162160
});
161+
162+
db.on('close', function() {
163+
var message = 'Mongo connection closed';
164+
console.warn(message);
165+
self.emit('close', message);
166+
});
167+
168+
self.db = db.db(self.name);
169+
authenticateUser(auth);
163170
}
164171
});
165172
} else {

npm-shrinkwrap.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "fh-db",
33
"description": "FeedHenry Database Library",
4-
"version": "1.2.3",
4+
"version": "1.2.4",
55
"repository": {
66
"type": "git",
77
"url": "git@github.com:feedhenry/fh-db.git"

sonar-project.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
sonar.projectKey=fh-db
22
sonar.projectName=fh-db-nightly-master
3-
sonar.projectVersion=1.2.3
3+
sonar.projectVersion=1.2.4
44

55
sonar.sources=./lib
66
sonar.tests=./test

0 commit comments

Comments
 (0)