0
votes

The error object that is returned from breeze manager saveChanges() don't have the array entitiesWithErrors, but instead has the entityErrors array (perhaps is as it is on breeze.js version: 1.4.12, metadataVersion: 1.0.5)

The returned error object looks like...

Error {stack: "Error: Client side validation errors encountered", entityErrors: Array[6], message: "Client side validation errors encountered see the Errors collection on this object for more detail" entityErrors: Array[6] bla. bla..

Thus the code bellow will fail and I will need to refactor it if I am not able to work with entitiesWithErrors

function getErrorMessages(error) {
    function getValidationMessages(err) {
        try {
            return err.entitiesWithErrors.map(function (entity) {
                return entity.entityAspect.getValidationErrors().map(function (valError) {
                    return valError.errorMessage;
                }).join('; <br/>');
            }).join('; <br/>');
        } catch (e) {

        }
        return 'validation error';
    }
    var msg = error.message;
    if (msg.match(/validation error/i)) {
        return getValidationMessages(error);
    }
    return msg;
}
1

1 Answers

2
votes

This breaking change was made in Breeze version 1.4.0. From the release notes,

The description of client side validation errors caught during a save before posting to the server has changed.

Client side validation errors caught during a save, but before posting to the server, cause the save to fail and be routed to the fail promise. The fail promise returns an error object that contains a description of the errors. This description has changed.

Previously this error object contained an entitiesWithErrors property that contained a list of all of the entities that had failed validation. This property has now been replaced with the entityErrors property. The entityErrors property returns a collection of entityError objects as described above.

This change was made in order to retain consistency between save failures that occurred on the server and those that failed before posting to the server on the client.

To refactor your code, you simply do,

return error.entityErrors.map(function (entityError) {
  return entityError.errorMessage;
})