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

Commit

Permalink
fix(errors): throw MongoNetworkError from more places
Browse files Browse the repository at this point in the history
NODE-1080
  • Loading branch information
Sebastian Hallum Clarke authored and mbroadst committed Aug 6, 2017
1 parent 47b3746 commit 2cec239
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
8 changes: 4 additions & 4 deletions lib/connection/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var inherits = require('util').inherits
, parseHeader = require('../wireprotocol/shared').parseHeader
, decompress = require('../wireprotocol/compression').decompress
, Response = require('./commands').Response
, MongoError = require('../error')
, MongoNetworkError = require('../network_error')
, Logger = require('./logger')
, zlib = require('zlib')
, Snappy = require('./utils').retrieveSnappy()
Expand Down Expand Up @@ -190,7 +190,7 @@ var errorHandler = function(self) {
// Debug information
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)));
// Emit the error
if(self.listeners('error').length > 0) self.emit("error", MongoError.create(err), self);
if(self.listeners('error').length > 0) self.emit("error", MongoNetworkError.create(err), self);
}
}

Expand All @@ -201,7 +201,7 @@ var timeoutHandler = function(self) {
if(self.logger.isDebug()) self.logger.debug(f('connection %s for [%s:%s] timed out', self.id, self.host, self.port));
// Emit timeout error
self.emit("timeout"
, MongoError.create(f("connection %s to %s:%s timed out", self.id, self.host, self.port))
, MongoNetworkError.create(f("connection %s to %s:%s timed out", self.id, self.host, self.port))
, self);
}
}
Expand All @@ -215,7 +215,7 @@ var closeHandler = function(self) {
// Emit close event
if(!hadError) {
self.emit("close"
, MongoError.create(f("connection %s to %s:%s closed", self.id, self.host, self.port))
, MongoNetworkError.create(f("connection %s to %s:%s closed", self.id, self.host, self.port))
, self);
}
}
Expand Down
5 changes: 3 additions & 2 deletions lib/wireprotocol/3_2_support.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var Query = require('../connection/commands').Query
, retrieveBSON = require('../connection/utils').retrieveBSON
, f = require('util').format
, MongoError = require('../error')
, MongoNetworkError = require('../network_error')
, getReadPreference = require('./shared').getReadPreference;

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

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

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

// Raw, return all the extracted documents
Expand Down

0 comments on commit 2cec239

Please sign in to comment.