uwburn / mongoose-errors-helper

A utility module to deal with Mongoose in web APIs development.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.

About

A utility module to deal with Mongoose in web APIs development.


Languages

Language:JavaScript 100.0%