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

Commit

Permalink
feat(Error): adding error metadata field
Browse files Browse the repository at this point in the history
  • Loading branch information
daprahamian authored May 24, 2018
1 parent 38d5f40 commit 33be560
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
19 changes: 13 additions & 6 deletions lib/cursor.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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();
Expand Down
7 changes: 6 additions & 1 deletion lib/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

var util = require('util');

const mongoErrorContextSymbol = Symbol('mongoErrorContextSymbol');

/**
* Creates a new MongoError
* @class
Expand Down Expand Up @@ -31,6 +33,8 @@ function MongoError(message) {
Error.captureStackTrace(this, this.constructor);
}
}

this[mongoErrorContextSymbol] = this[mongoErrorContextSymbol] || {};
}
util.inherits(MongoError, Error);

Expand Down Expand Up @@ -94,5 +98,6 @@ module.exports = {
MongoError,
MongoNetworkError,
MongoParseError,
MongoTimeoutError
MongoTimeoutError,
mongoErrorContextSymbol
};

0 comments on commit 33be560

Please sign in to comment.