diff --git a/index.js b/index.js index 03d392493..bf9e14da5 100644 --- a/index.js +++ b/index.js @@ -16,6 +16,7 @@ try { module.exports = { MongoError: require('./lib/error').MongoError, MongoNetworkError: require('./lib/error').MongoNetworkError, + mongoErrorContextSymbol: require('./lib/error').mongoErrorContextSymbol, Connection: require('./lib/connection/connection'), Server: require('./lib/topologies/server'), ReplSet: require('./lib/topologies/replset'), diff --git a/lib/cursor.js b/lib/cursor.js index ff9f72896..38aaadc70 100644 --- a/lib/cursor.js +++ b/lib/cursor.js @@ -1,10 +1,11 @@ 'use strict'; -var Logger = require('./connection/logger'), - retrieveBSON = require('./connection/utils').retrieveBSON, - MongoError = require('./error').MongoError, - MongoNetworkError = require('./error').MongoNetworkError, - f = require('util').format; +const Logger = require('./connection/logger'); +const retrieveBSON = require('./connection/utils').retrieveBSON; +const MongoError = require('./error').MongoError; +const MongoNetworkError = require('./error').MongoNetworkError; +const mongoErrorContextSymbol = require('./error').mongoErrorContextSymbol; +const f = require('util').format; var BSON = retrieveBSON(), Long = BSON.Long; @@ -709,7 +710,13 @@ var nextFunction = function(self, callback) { // Execute the next get more self._getmore(function(err, doc, connection) { - if (err) return handleCallback(callback, err); + if (err) { + if (err instanceof MongoError) { + err[mongoErrorContextSymbol].isGetMore = true; + } + + return handleCallback(callback, err); + } if (self.cursorState.cursorId && self.cursorState.cursorId.isZero() && self._endSession) { self._endSession(); diff --git a/lib/error.js b/lib/error.js index 5a40f6327..6a8c1a420 100644 --- a/lib/error.js +++ b/lib/error.js @@ -2,6 +2,8 @@ var util = require('util'); +const mongoErrorContextSymbol = Symbol('mongoErrorContextSymbol'); + /** * Creates a new MongoError * @class @@ -31,6 +33,8 @@ function MongoError(message) { Error.captureStackTrace(this, this.constructor); } } + + this[mongoErrorContextSymbol] = this[mongoErrorContextSymbol] || {}; } util.inherits(MongoError, Error); @@ -94,5 +98,6 @@ module.exports = { MongoError, MongoNetworkError, MongoParseError, - MongoTimeoutError + MongoTimeoutError, + mongoErrorContextSymbol };