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

Commit 2cec239

Browse files
Sebastian Hallum Clarkembroadst
Sebastian Hallum Clarke
authored andcommitted
fix(errors): throw MongoNetworkError from more places
NODE-1080
1 parent 47b3746 commit 2cec239

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

lib/connection/connection.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ var inherits = require('util').inherits
1010
, parseHeader = require('../wireprotocol/shared').parseHeader
1111
, decompress = require('../wireprotocol/compression').decompress
1212
, Response = require('./commands').Response
13-
, MongoError = require('../error')
13+
, MongoNetworkError = require('../network_error')
1414
, Logger = require('./logger')
1515
, zlib = require('zlib')
1616
, Snappy = require('./utils').retrieveSnappy()
@@ -190,7 +190,7 @@ var errorHandler = function(self) {
190190
// Debug information
191191
if(self.logger.isDebug()) self.logger.debug(f('connection %s for [%s:%s] errored out with [%s]', self.id, self.host, self.port, JSON.stringify(err)));
192192
// Emit the error
193-
if(self.listeners('error').length > 0) self.emit("error", MongoError.create(err), self);
193+
if(self.listeners('error').length > 0) self.emit("error", MongoNetworkError.create(err), self);
194194
}
195195
}
196196

@@ -201,7 +201,7 @@ var timeoutHandler = function(self) {
201201
if(self.logger.isDebug()) self.logger.debug(f('connection %s for [%s:%s] timed out', self.id, self.host, self.port));
202202
// Emit timeout error
203203
self.emit("timeout"
204-
, MongoError.create(f("connection %s to %s:%s timed out", self.id, self.host, self.port))
204+
, MongoNetworkError.create(f("connection %s to %s:%s timed out", self.id, self.host, self.port))
205205
, self);
206206
}
207207
}
@@ -215,7 +215,7 @@ var closeHandler = function(self) {
215215
// Emit close event
216216
if(!hadError) {
217217
self.emit("close"
218-
, MongoError.create(f("connection %s to %s:%s closed", self.id, self.host, self.port))
218+
, MongoNetworkError.create(f("connection %s to %s:%s closed", self.id, self.host, self.port))
219219
, self);
220220
}
221221
}

lib/wireprotocol/3_2_support.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ var Query = require('../connection/commands').Query
44
, retrieveBSON = require('../connection/utils').retrieveBSON
55
, f = require('util').format
66
, MongoError = require('../error')
7+
, MongoNetworkError = require('../network_error')
78
, getReadPreference = require('./shared').getReadPreference;
89

910
var BSON = retrieveBSON(),
@@ -124,7 +125,7 @@ WireProtocol.prototype.killCursor = function(bson, ns, cursorId, pool, callback)
124125
// If we have a timed out query or a cursor that was killed
125126
if((r.responseFlags & (1 << 0)) != 0) {
126127
if(typeof callback != 'function') return;
127-
return callback(new MongoError("cursor killed or timed out"), null);
128+
return callback(new MongoNetworkError("cursor killed or timed out"), null);
128129
}
129130

130131
if(!Array.isArray(r.documents) || r.documents.length == 0) {
@@ -182,7 +183,7 @@ WireProtocol.prototype.getMore = function(bson, ns, cursorState, batchSize, raw,
182183

183184
// If we have a timed out query or a cursor that was killed
184185
if((r.responseFlags & (1 << 0)) != 0) {
185-
return callback(new MongoError("cursor killed or timed out"), null);
186+
return callback(new MongoNetworkError("cursor killed or timed out"), null);
186187
}
187188

188189
// Raw, return all the extracted documents

0 commit comments

Comments
 (0)