Concurrency/ToDo Sample not working

2019-03-03 07:14发布

问题:

I was trying out the ToDo sample and ran into an unhandled Excaption while trying out the Concurrency Handling.

The dataservice.js contains these lines in saveFailed(error) method:

if (detail && detail.ExceptionType.indexOf('OptimisticConcurrencyException') !== -1) {
        // Concurrency error 
        reason =
            "Another user, perhaps the server, may have deleted one or all of the todos.";
        manager.rejectChanges(); // DEMO ONLY: discard all pending changes
    }

The client never gets to this point due to an unhandled OptimisticConcurrencyException in:

[HttpPost]
    public SaveResult SaveChanges(JObject saveBundle) {
        return _contextProvider.SaveChanges(saveBundle);
    }

I was trying to catch this and return the Exception which was kind of stupid as the Exception is not of type SaveResult. Is this a bug or am i missing an configuration somewhere?

Greets

回答1:

Any server side errors should be returned to the promise.fail handler. i.e.

em.saveChanges().then(function(saveResult) {
   // normal path

}).fail(function(error) {
   // your concurrency exception message will be part of the error object. 
});


回答2:

Error on my side here... Clicking 'Continue' on the Exception Windows in VS the javascript handler is executed.



标签: breeze