PageRenderTime 18ms CodeModel.GetById 10ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/node_modules/mongodb-core/lib/error.js

https://bitbucket.org/coleman333/smartsite
JavaScript | 44 lines | 23 code | 6 blank | 15 comment | 9 complexity | 71fd0c6c415d35bf8c29b80eafc6e69f MD5 | raw file
 1"use strict";
 2
 3/**
 4 * Creates a new MongoError
 5 * @class
 6 * @augments Error
 7 * @param {string} message The error message
 8 * @return {MongoError} A MongoError instance
 9 */
10function MongoError(message) {
11  this.name = 'MongoError';
12  this.message = message;
13  Error.captureStackTrace(this, MongoError);
14}
15
16/**
17 * Creates a new MongoError object
18 * @method
19 * @param {object} options The error options
20 * @return {MongoError} A MongoError instance
21 */
22MongoError.create = function(options) {
23  var err = null;
24
25  if(options instanceof Error) {
26    err = new MongoError(options.message);
27    err.stack = options.stack;
28  } else if(typeof options == 'string') {
29    err = new MongoError(options);
30  } else {
31    err = new MongoError(options.message || options.errmsg || options.$err || "n/a");
32    // Other options
33    for(var name in options) {
34      err[name] = options[name];
35    }
36  }
37
38  return err;
39}
40
41// Extend JavaScript error
42MongoError.prototype = new Error;
43
44module.exports = MongoError;