Cleanup
This commit is contained in:
11
node_modules/mongoose/lib/error/validation.js
generated
vendored
11
node_modules/mongoose/lib/error/validation.js
generated
vendored
@@ -4,10 +4,10 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
const MongooseError = require('./');
|
||||
const MongooseError = require('./mongooseError');
|
||||
const getConstructorName = require('../helpers/getConstructorName');
|
||||
const util = require('util');
|
||||
|
||||
|
||||
class ValidationError extends MongooseError {
|
||||
/**
|
||||
* Document Validation Error
|
||||
@@ -18,7 +18,7 @@ class ValidationError extends MongooseError {
|
||||
*/
|
||||
constructor(instance) {
|
||||
let _message;
|
||||
if (instance && instance.constructor.name === 'model') {
|
||||
if (getConstructorName(instance) === 'model') {
|
||||
_message = instance.constructor.modelName + ' validation failed';
|
||||
} else {
|
||||
_message = 'Validation failed';
|
||||
@@ -68,13 +68,14 @@ if (util.inspect.custom) {
|
||||
|
||||
/*!
|
||||
* Helper for JSON.stringify
|
||||
* Ensure `name` and `message` show up in toJSON output re: gh-9847
|
||||
*/
|
||||
Object.defineProperty(ValidationError.prototype, 'toJSON', {
|
||||
enumerable: false,
|
||||
writable: false,
|
||||
configurable: true,
|
||||
value: function() {
|
||||
return Object.assign({}, this, { message: this.message });
|
||||
return Object.assign({}, this, { name: this.name, message: this.message });
|
||||
}
|
||||
});
|
||||
|
||||
@@ -108,4 +109,4 @@ function _generateMessage(err) {
|
||||
* Module exports
|
||||
*/
|
||||
|
||||
module.exports = exports = ValidationError;
|
||||
module.exports = ValidationError;
|
||||
|
||||
Reference in New Issue
Block a user