1.0.0 • Published 5 years ago

mongoose-errors-helper v1.0.0

Weekly downloads
2
License
LGPL-3.0
Repository
github
Last release
5 years ago

Mongoose Helper

A utility module to deal with Mongoose in web APIs development. Currently supports validation errors checking and extraction. Might be extended for future needs.

Usage

var mongooseHelper = require('mongoose-helper');

var models = require('./models');

var entity = new models.Entity({ /* Some props */ });
entity.save().then(function(savedEntity) {
    // Do something
}).catch(function(err) {
    if (mongooseHelper.isValidationError(err)) {
		var errors = mongooseHelper.getValidationErrors(err);
		// Do something with the errors extracted
	}
});

Notes

The errors are extracted as an array of strings.