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

Commit

Permalink
fix(errors): use util.inherits() and protect edge case
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Hallum Clarke authored and mbroadst committed Aug 6, 2017
1 parent a132830 commit c953246
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lib/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ var util = require('util');
* @return {MongoError} A MongoError instance
*/
function MongoError(message) {
this.name = 'MongoError';
var tmp = Error.apply(this, arguments);
tmp.name = this.name = 'MongoError';

if (message instanceof Error) {
this.message = message.message;
Expand All @@ -26,9 +27,12 @@ function MongoError(message) {
this[name] = message[name];
}
}
Error.captureStackTrace(this, MongoError);
if (Error.captureStackTrace) {
Error.captureStackTrace(this, this.constructor);
}
}
}
util.inherits(MongoError, Error);

/**
* Creates a new MongoError object
Expand All @@ -41,9 +45,6 @@ MongoError.create = function(options) {
return new MongoError(options);
}

// Extend JavaScript error
MongoError.prototype = new Error;

/**
* Creates a new MongoNetworkError
* @class
Expand Down

0 comments on commit c953246

Please sign in to comment.