This repository has been archived by the owner on Feb 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(errors): use subclassing for MongoNetworkError
- Loading branch information
Showing
29 changed files
with
164 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,65 @@ | ||
"use strict"; | ||
|
||
var util = require('util'); | ||
|
||
/** | ||
* Creates a new MongoError | ||
* @class | ||
* @augments Error | ||
* @param {string} message The error message | ||
* @param {Error|string|object} message The error message | ||
* @property {string} message The error message | ||
* @property {string} stack The error call stack | ||
* @return {MongoError} A MongoError instance | ||
*/ | ||
function MongoError(message) { | ||
this.name = 'MongoError'; | ||
this.message = message; | ||
Error.captureStackTrace(this, MongoError); | ||
|
||
if (message instanceof Error) { | ||
this.message = message.message; | ||
this.stack = message.stack; | ||
} else { | ||
if (typeof message === 'string') { | ||
this.message = message; | ||
} else { | ||
this.message = message.message || message.errmsg || message.$err || 'n/a'; | ||
for (var name in message) { | ||
this[name] = message[name]; | ||
} | ||
} | ||
Error.captureStackTrace(this, MongoError); | ||
} | ||
} | ||
|
||
/** | ||
* Creates a new MongoError object | ||
* @method | ||
* @param {Error|string|object} options The options used to create the error. | ||
* @return {MongoError} A MongoError instance | ||
* @deprecated Use new MongoError() instead. | ||
*/ | ||
MongoError.create = function(options) { | ||
var err = null; | ||
|
||
if(options instanceof Error) { | ||
err = new MongoError(options.message); | ||
err.stack = options.stack; | ||
} else if(typeof options == 'string') { | ||
err = new MongoError(options); | ||
} else { | ||
err = new MongoError(options.message || options.errmsg || options.$err || "n/a"); | ||
// Other options | ||
for(var name in options) { | ||
err[name] = options[name]; | ||
} | ||
} | ||
|
||
return err; | ||
return new MongoError(options); | ||
} | ||
|
||
// Extend JavaScript error | ||
MongoError.prototype = new Error; | ||
|
||
module.exports = MongoError; | ||
/** | ||
* Creates a new MongoNetworkError | ||
* @class | ||
* @param {Error|string|object} message The error message | ||
* @property {string} message The error message | ||
* @property {string} stack The error call stack | ||
* @return {MongoNetworkError} A MongoNetworkError instance | ||
* @extends {MongoError} | ||
*/ | ||
var MongoNetworkError = function(message) { | ||
MongoError.call(this, message); | ||
this.name = 'MongoNetworkError'; | ||
}; | ||
util.inherits(MongoNetworkError, MongoError); | ||
|
||
module.exports = { | ||
MongoError: MongoError, | ||
MongoNetworkError: MongoNetworkError | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.