thoughts/node_modules/mongoose/lib/errors/validation.js
node_modules/mongoose/lib/errors/validation.jsRaw
1
2/*!
3 * Module requirements
4 */
5
6var MongooseError = require('../error')
7
8/**
9 * Document Validation Error
10 *
11 * @api private
12 * @param {Document} instance
13 * @inherits MongooseError
14 */
15
16function ValidationError (instance) {
17 MongooseError.call(this, "Validation failed");
18 Error.captureStackTrace(this, arguments.callee);
19 this.name = 'ValidationError';
20 this.errors = instance.errors = {};
21};
22
23/**
24 * Console.log helper
25 */
26
27ValidationError.prototype.toString = function () {
28 var ret = this.name + ': ';
29 var msgs = [];
30
31 Object.keys(this.errors).forEach(function (key) {
32 if (this == this.errors[key]) return;
33 msgs.push(String(this.errors[key]));
34 }, this)
35
36 return ret + msgs.join(', ');
37};
38
39/*!
40 * Inherits from MongooseError.
41 */
42
43ValidationError.prototype.__proto__ = MongooseError.prototype;
44
45/*!
46 * Module exports
47 */
48
49module.exports = exports = ValidationError;