English 中文(简体)
ServiceStack: how to deal with errors?
原标题:

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)

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.

最佳回答

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

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

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

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

问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签