Question

I have read through the breeze validator information, but am not sure how to view the actual error that is occurring.

Error: client side validation errors encountered - see the entity Errors collection on this object for more detail.

I believe it's somewhere in entity.entityAspect.getValidationErrors() but am having trouble figuring out how to get the actual error out of it.

I am trying to insert a record into an entity and save changes when this error message occurs.

Was it helpful?

Solution

See :

http://www.breezejs.com/sites/all/apidocs/classes/ValidationError.html

http://www.breezejs.com/sites/all/apidocs/classes/EntityAspect.html#method_getValidationErrors

Simple example:

var errors = entity.entityAspect.getValidationErrors();
errors.forEach(function(ve) {
   var errorMessage = ve.errorMessage;
   var property = ve.property;
});

To get all of the errors in an EntityManager you can use

manager.getEntities().forEach(function(entity) { 
   var errors = entity.entityAspect.getValidationErrors();
   //.. do something with the errors ..
});

OTHER TIPS

You can 'catch' the errors when you try and save, like so:

manager.saveChanges()
  .catch(function(error){
      console.log("error catch", error, error.entityErrors);
  });

Just keep in mind that any code after that will need to be in a

setTimeout(function() {}, 0);

as the catch is async. This was you don't need to loop through all the entities in the app to find the ones with errors.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top