ServiceStack: how to deal with errors?

I am using ServiceStack with excellent results so far, except that dealing with errors seems complicated. If something went wrong during serialization of the message (because I forgot to add a default constructor to the message, for example), the entire client returns - this is a message stating that the server had an internal error and status code 500. Adding a listener to the event HttpApplication.Error in Global.asax does not work, since it never hits. Also there is no Application_Error . Not only is this not enough for end-user scripts, it makes debugging these errors very cumbersome, as the only way to find out what went wrong is with the ugly expression in Quick Watch:

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

What I would like is to catch any errors on the server side (be it ServiceStack serialization or errors in my services) and add the necessary information to the Errors collection, which has all my message types.

+7
source share
1 answer

For more information about handling and checking errors in ServiceStack, see the ServiceStack Verification and Error wiki.

There is currently no way to handle serialization exception with custom logic (although now I will add this to the TODO list :).

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

To get your StackTrace DebugMode set serialized to true using SetConfig () in your AppHost.Configure () onload script.

+11
source

All Articles