ServiceStack:如何处理错误? [英] ServiceStack: how to deal with errors?

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

问题描述

我使用ServiceStack很大的成绩,到目前为止,除了处理错误似乎是棘手。如果有什么消息的序列化过程中出现问题(因为我忘了一个默认的构造函数添加到例如消息)所有的客户端回来一个消息,服务器有一个内部错误和500状态code添加一个监听到 HttpApplication.Error 事件在Global.asax不工作,因为它从来没有被击中。无论是做的Application_Error 。这不仅是不够的最终用户的情况下,它使调试这些错误非常麻烦,因为找出的唯一方法出了什么问题是这个丑陋的EX pression在快速监视:

I'm using ServiceStack with great results so far, except that dealing with errors is seemingly tricky. If something goes wrong during serialization of a message (because I forgot to add a default constructor to the message for example) all the client gets back is a message that the server had an internal error and a status code of 500. Adding a listener to the HttpApplication.Error event in the Global.asax doesn't work as it never gets hit. Neither does Application_Error. Not only is this insufficient for end user scenarios, it makes debugging these errors very cumbersome as the only way to find out what went wrong is this ugly expression in the Quick Watch:

Encoding.Default.GetString( ((System.IO.MemoryStream)((SyncMemoryStream)((System.Net.HttpWebResponse)(((WebException)ex).Response)).ResponseStream))._buffer)

我想是在服务器端捕捉任何和所有的错误(无论是通过序列化ServiceStack,或错误在我的服务),并添加所需的信息的错误集合,我所有的消息类型有。

What I'd like is catch any and all errors on the server side (be it serialization by ServiceStack, or errors on my services) and add the required information to an Errors collection that all my message types have.

推荐答案

请参阅ServiceStack的验证和错误处理维基页有关错误处理和验证的ServiceStack更多细节。

See ServiceStack's Validation and Error handling wiki page for more details about error handling and validation in ServiceStack.

目前没有办法来处理序列化异常,自定义逻辑(尽管我现在补充说,TODO列表:)。

At the moment there is no way to handle a serialization exception with Custom logic (although I will now add that on the TODO list :).

如果您回应DTO有一个 ResponseStatus 属性(即或继承IHasResponseStatus),ServiceStack应自动序列化你的异常。

If your Response DTO has a ResponseStatus property (i.e. or inherits from IHasResponseStatus), ServiceStack should automatically serialize your exception.

要还让它序列化堆栈跟踪将 DebugMode 以真与SetConfig()在你的AppHost.Configure()的onload脚本。

To also get it to serialize your StackTrace set DebugMode to true with SetConfig() in your AppHost.Configure() onload script.

这篇关于ServiceStack:如何处理错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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