Mr.Wang from Next Door
Mr.Wang from Next Door

Reputation: 14820

ServiceStack unwrap exception automatically

I found ServiceStack 4 unwrap the exception automatically, how to prevent that?

For example, I have the following API exposed.

public async Task GET(XXXRequest request)
{
    try
    {
    throw new Exception("#inner");
    }
    catch(Exception ex)
    {
    throw new Exception("#outer", ex);
    }
}

And I have a logger capturing the errors

Plugins.Add(new RequestLogsFeature()
{
  EnableRequestBodyTracking = true,
  EnableResponseTracking = true,
  EnableErrorTracking = true,
  RequestLogger = new CustomRequestLogger()
});

class CustomRequestLogger : InMemoryRollingRequestLogger
{

    public override void Log(IRequest request, object requestDto, object response, TimeSpan requestDuration)
    {
        base.Log(request, requestDto, response, requestDuration);

        // handle errors
        HttpError httpError = response as HttpError;
        if (httpError != null)
        {
            // log error
        // httpError is #inner
        return;
        }
    }
}

The problem is that: I only captured the inner exception, the outer exception disappeared

enter image description here

Upvotes: 1

Views: 86

Answers (1)

mythz
mythz

Reputation: 143399

You can disable this in your AppHost with:

SetConfig(new HostConfig {
    ReturnsInnerException = false,
});

Upvotes: 3

Related Questions