npm

Ready to take your JavaScript development to the next level? Meet npm Enterprise - the ultimate in enterprise JavaScript.Learn more »

mongoose-ember-errors

0.0.5 • Public • Published

Mongoose Ember Errors

Simple tool to convert Mongoose's ValidationError into Ember-Data compatible.

Install

npm install mongoose-ember-errors --save

Usage

var EmberErrors = require('mongoose-ember-errors');
 
model.save(function(err) {
  // err contains normal ValidationError
  err = new EmberErrors(err);
});
 

The conversion looks similar to this:

{ [ValidationError: Schema validation failed]
  message: 'Schema validation failed',
  name: 'ValidationError',
  errors:
   { testObjectId:
      { [CastError: Cast to ObjectID failed for value "test" at path "testObjectId"]
        message: 'Cast to ObjectID failed for value "test" at path "testObjectId"',
        name: 'CastError',
        kind: 'ObjectID',
        value: 'test',
        path: 'testObjectId' },
     testField:
      { [ValidatorError: Path `testField` is required.]
        properties: [Object],
        message: 'Path `testField` is required.',
        name: 'ValidatorError',
        kind: 'required',
        path: 'testField',
        value: undefined } } }

Into:

{ [Error: Schema validation failed]
  message: 'Schema validation failed',
  errors:
   { testObjectId: [ 'test is invalid' ],
     testField: [ 'Path `testField` is required.' ] } }

install

npm i mongoose-ember-errors

Downloadsweekly downloads

16

version

0.0.5

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability