File tree Expand file tree Collapse file tree 2 files changed +21
-1
lines changed
Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Original file line number Diff line number Diff 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 ) ;
Original file line number Diff line number Diff 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' ,
You can’t perform that action at this time.
0 commit comments