Skip to content
This repository has been archived by the owner on Feb 4, 2022. It is now read-only.

Commit

Permalink
fix(connect): fixed syntax issue in connect error handler
Browse files Browse the repository at this point in the history
Connect error handler was attempting to read properties off
of an error that had a chance of being null. Removed that,
and replaced the error generation to be more explicit.

Fixes NODE-1960
  • Loading branch information
daprahamian committed May 15, 2019
1 parent 5e53b0e commit 83e224b
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions lib/connection/connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,10 +281,9 @@ function makeConnection(family, options, _callback) {
const errorEvents = ['error', 'close', 'timeout', 'parseError', 'connect'];
function errorHandler(eventName) {
return err => {
if (err == null || err === false) err = true;
errorEvents.forEach(event => socket.removeAllListeners(event));
socket.removeListener('connect', connectHandler);
callback(new MongoNetworkError(err.message), eventName);
callback(connectionFailureError(eventName, err), eventName);
};
}

Expand Down Expand Up @@ -355,4 +354,17 @@ function authenticate(conn, credentials, callback) {
});
}

function connectionFailureError(type, err) {
switch (type) {
case 'error':
return new MongoNetworkError(err);
case 'timeout':
return new MongoNetworkError(`connection timed out`);
case 'close':
return new MongoNetworkError(`connection closed`);
default:
return new MongoNetworkError(`unknown network error`);
}
}

module.exports = connect;

0 comments on commit 83e224b

Please sign in to comment.