OptimisticConcurrencyException [英] OptimisticConcurrencyException

查看:63
本文介绍了OptimisticConcurrencyException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

未正确返回Optimistic ConcurrencyException。我用微风的ToDo示例和我的应用程序对此进行了测试。

The Optimistic ConcurrencyException is not returned right. I tested this with the breeze ToDo sample and my app.

如果我引发OptimisticConcurrencyException,则返回以下内容:

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."}

缺少ExceptionType。

The ExceptionType is missing. In debug-mode in VS this works right.

推荐答案

@sascha-您在< customErrors> 可以在IIS中运行的情况下正常工作(请参见吉米·博加德(Jimmy Bogard)的替代选择(如果您是能够自我托管Web Api的极少数人之一)。

@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).

但是我很确定最终这样做是错误的。目前这是权宜之计,但正如Jimmy在他的帖子中所说:我们生产中可能不需要这些东西。应用程序不应将诸如乐观并发或验证错误之类的常规内容暴露给客户端。

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.

我打算找到一种更好的方法,最有可能涉及到 HttpResponseException,如此处所述。我将强烈考虑自定义异常过滤器,以便以受控方式处理未处理的异常。

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.

我不认为那种方法是Breeze本身的东西。令我感到震惊的是,它需要一种特定于应用程序的解决方案……一种知道应该公开哪些异常以及如何对其表达的方式。但是,该机制将非常有用。一旦知道了如何做,您就可以滚动自己的自定义异常处理……而不必理会Web.config。

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 :)

这篇关于OptimisticConcurrencyException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆