问题
The Optimistic ConcurrencyException is not returned right. I tested this with the breeze ToDo sample and my app.
This is what is returned if i provoke a an OptimisticConcurrencyException:
{"$id":"1","$type":"System.Web.Http.HttpError, System.Web.Http","Message":"An error has occurred."}
The ExceptionType is missing. In debug-mode in VS this works right.
回答1:
@sascha - You beat me to it on the <customErrors>
thing which works fine if you're running in IIS (see Jimmy Bogard's alternative if you are one of the very few who would self-host your Web Api).
But I’m pretty sure it is the wrong thing to do ultimately. It is expedient for now but, as Jimmy says in his post, “It’s likely not something we want in production.” An app shouldn’t expose unfiltered exceptions to the client for routine stuff like optimistic concurrency or validation errors.
I intend to find a better approach, most likely involving the HttpResponseException as described here. I'll give strong consideration to a “Custom Exception Filter” for dealing with unhandled exceptions in a controlled manner.
I don’t think that approach is something that belongs in Breeze itself. It strikes me as requiring an application specific solution … one that knows which exceptions should be exposed and how they should be phrased. But the mechanism would be good to teach. Once you know how to do it, you can roll your own custom exception handling ... and leave the Web.config alone.
Hoping to write this guidance soon. Feel free to beat me to it :)
回答2:
Hm..., when I attempt a concurrency exception in my test cases.
// assuming this causes a concurrency exception
em.saveChanges().then(
).fail(function(error) {
// error object detailed below
})
I get the following returned with the 'error' parameter
error.message: "Store update, insert, or delete statement affected an unexpected number of rows (0). Entities may have been modified or deleted since entities were loaded. Refresh ObjectStateManager entries."
error.responseText: {"$id":"1","$type":"System.Web.Http.HttpError, System.Web.Http","Message":"An error has occurred.","ExceptionMessage":"Store update, insert, or delete statement affected an unexpected number of rows (0). Entities may have been modified or deleted since entities were loaded. Refresh ObjectStateManager entries.","ExceptionType":"System.Data.OptimisticConcurrencyException","StackTrace":" at System.Data.Mapping.Update.Internal.UpdateTranslator.ValidateRowsAffected(Int64 <... more here ...> }
error.detail: < an even more detailed error object
error.detail.ExceptionType: "System.Data.OptimisticConcurrencyException"
There are other properties but these are the important ones.
I wonder what we are doing differently?
来源:https://stackoverflow.com/questions/13876458/optimisticconcurrencyexception