Skip to content

Commit 1f6be24

Browse files
committed
Merge pull request #593 from romanfromrome/rz-error-check-issue
fixed thrown error check
2 parents 3b13f19 + fbb53fa commit 1f6be24

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

lib/ORM.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ exports.connect = function (opts, cb) {
134134
db.emit("connect", err, !err ? db : null);
135135
});
136136
} catch (ex) {
137-
if (ex.code === "MODULE_NOT_FOUND" || ex.message.indexOf('find module')) {
137+
if (ex.code === "MODULE_NOT_FOUND" || ex.message.indexOf('find module') > -1) {
138138
return ORM_Error(new ORMError("Connection protocol not supported - have you installed the database driver for " + proto + "?", 'NO_SUPPORT'), cb);
139139
}
140140
return ORM_Error(ex, cb);

test/integration/orm-exports.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,26 @@ describe("ORM.connect()", function () {
139139
});
140140
});
141141

142+
it("should emit valid error if exception being thrown during connection try", function (done) {
143+
var testConfig = {
144+
protocol : 'mongodb',
145+
href : 'unknownhost',
146+
database : 'unknowndb',
147+
user : '',
148+
password : ''
149+
},
150+
db = ORM.connect(testConfig);
151+
152+
db.on("connect", function (err) {
153+
should.exist(err);
154+
should.equal(err.message.indexOf("Connection protocol not supported"), -1);
155+
err.message.should.not.equal("CONNECTION_URL_NO_PROTOCOL");
156+
err.message.should.not.equal("CONNECTION_URL_EMPTY");
157+
158+
return done();
159+
});
160+
});
161+
142162
it("should not modify connection opts", function (done) {
143163
var opts = {
144164
protocol : 'mysql',

0 commit comments

Comments
 (0)