syntagma / mongoose-error-helper Goto Github PK
View Code? Open in Web Editor NEWError helper for mongoose error complex messages. Transform field validators into human readable arrays.
License: MIT License
Error helper for mongoose error complex messages. Transform field validators into human readable arrays.
License: MIT License
When installing your NPM package, i get this code
/**
* Created with IntelliJ IDEA.
* User: sebastianbromberg
* Date: 12/8/13
* Time: 15:58
* To change this template use File | Settings | File Templates.
*/
var util = require('util');
exports.errorHelper = function errorHelper(err) {
//If it isn't a mongoose-validation error, just throw it.
if (err.name !== 'ValidationError') return err;
var messages = {
'required': "%s is required.",
'min': "%s below minimum.",
'max': "%s above maximum.",
'enum': "%s not an allowed value."
};
//A validationerror can contain more than one error.
var errors = [];
//Loop over the errors object of the Validation Error
Object.keys(err.errors).forEach(function (field) {
var eObj = err.errors[field];
//If we don't have a message for `type`, just push the error through
if (!messages.hasOwnProperty(eObj.type)) errors.push(eObj.type);
//Otherwise, use util.format to format the message, and passing the path
else errors.push(util.format(messages[eObj.type], eObj.path));
});
return errors;
}
where var eObj = err.errors[field];
don't get properties so it push eObj.type
which is equal to undefined
Your documentation show that you can use 'next' or callback as second parameter but
only err it's used
exports.errorHelper = function errorHelper(err) {
Don't understand.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.