Sam
Sam

Reputation: 14596

breezejs: populate the error property of SaveResult

Currently when calling SaveChanges on the webapi controller, if a business rules is not satifisfied, we throw an exception with the error message. It's bad practice and instead we should return with the error property set to something, so that jQuery can handle it.

The problem is how are we supposed to populate the error property of the SaveResult object. How do we even get access to that object ?

Upvotes: 1

Views: 552

Answers (1)

Jay Traband
Jay Traband

Reputation: 17052

Good question! We are actually in the process of changing this for the next release, out either later this week or early next week. The "new" behavior will be that any server side validation exceptions that occur during the SaveChanges call will have two effects on the Breeze client.

1) The "fail" promise ( not the SaveResult, because this represents a failed save) will be called and the error returned will contain a "serverErrors" collection containing information on all of the validation errors encountered on the server, where each server error will be a separate json object with full error details including the entity and property (if available) that the error occurred on as well as an error message.

2) These errors will be automatically added to the appropriate entity.entityAspect's validationErrors collections, so any existing UI that uses the entityAspect.validationErrorsChanged notifications will work as expected.

Upvotes: 2

Related Questions