After looking at the first example at https://github.com/ServiceStack/ServiceStack/wiki/Error-Handling , I decided to check for DtoUtils .HandleException, which looks like this:
public static object HandleException(IResolver iocResolver, object request, Exception ex) { if (ex.InnerException != null && !(ex is IHttpError)) ex = ex.InnerException; var responseStatus = ex.ToResponseStatus(); if (EndpointHost.DebugMode) {
The very first instruction replaces the exception with an internal exception. I'm not sure what this is up to. It seems to me that it seems intuitive to me, and therefore I just repeated the method in the AppHost class, removing this first if if block:
public override void Configure(Container container) { ServiceExceptionHandler += (request, exception) => HandleException(this, request, exception); }
This is obviously not ideal, as I had to copy a bunch of code that is completely unrelated to the problem that I encountered with the original implementation. It seems to me that I should support this method whenever I update ServiceStack. I wish there was a better way to achieve this.
Anyway, I have exception handling that I like in my client code:
catch (WebServiceException ex) { if (ex.ErrorCode == typeof (SomeKindOfException).Name) { // do something useful here } else throw; }
source share