thoughts/node_modules/mongoose/lib/errors/validator.js
node_modules/mongoose/lib/errors/validator.jsRaw
1/*!
2 * Module dependencies.
3 */
4
5var MongooseError = require('../error');
6
7/**
8 * Schema validator error
9 *
10 * @param {String} path
11 * @param {String} msg
12 * @param {String|Number|any} val
13 * @inherits MongooseError
14 * @api private
15 */
16
17function ValidatorError (path, type, val) {
18 var msg = type
19 ? '"' + type + '" '
20 : '';
21
22 var message = 'Validator ' + msg + 'failed for path ' + path
23 if (2 < arguments.length) message += ' with value `' + String(val) + '`';
24
25 MongooseError.call(this, message);
26 Error.captureStackTrace(this, arguments.callee);
27 this.name = 'ValidatorError';
28 this.path = path;
29 this.type = type;
30 this.value = val;
31};
32
33/*!
34 * toString helper
35 */
36
37ValidatorError.prototype.toString = function () {
38 return this.message;
39}
40
41/*!
42 * Inherits from MongooseError
43 */
44
45ValidatorError.prototype.__proto__ = MongooseError.prototype;
46
47/*!
48 * exports
49 */
50
51module.exports = ValidatorError;