Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed thrown error check #593

Merged
merged 2 commits into from
Feb 6, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/ORM.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ exports.connect = function (opts, cb) {
db.emit("connect", err, !err ? db : null);
});
} catch (ex) {
if (ex.code === "MODULE_NOT_FOUND" || ex.message.indexOf('find module')) {
if (ex.code === "MODULE_NOT_FOUND" || ex.message.indexOf('find module') > -1) {
return ORM_Error(new ORMError("Connection protocol not supported - have you installed the database driver for " + proto + "?", 'NO_SUPPORT'), cb);
}
return ORM_Error(ex, cb);
Expand Down
20 changes: 20 additions & 0 deletions test/integration/orm-exports.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,26 @@ describe("ORM.connect()", function () {
});
});

it("should emit valid error if exception being thrown during connection try", function (done) {
var testConfig = {
protocol : 'mongodb',
href : 'unknownhost',
database : 'unknowndb',
user : '',
password : ''
},
db = ORM.connect(testConfig);

db.on("connect", function (err) {
should.exist(err);
should.equal(err.message.indexOf("Connection protocol not supported"), -1);
err.message.should.not.equal("CONNECTION_URL_NO_PROTOCOL");
err.message.should.not.equal("CONNECTION_URL_EMPTY");

return done();
});
});

it("should not modify connection opts", function (done) {
var opts = {
protocol : 'mysql',
Expand Down