我发现ServiceStack 4会自动解开异常,如何防止这种情况?
例如,我暴露了以下API。
public async Task GET(XXXRequest request)
{
try
{
throw new Exception("#inner");
}
catch(Exception ex)
{
throw new Exception("#outer", ex);
}
}
我有一个记录器捕获错误
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;
}
}
}
问题在于:我只捕获了内部异常,外部异常消失了
答案 0 :(得分:3)
您可以在AppHost中禁用此功能:
SetConfig(new HostConfig {
ReturnsInnerException = false,
});