服务堆栈处理异常

时间:2013-08-20 15:19:02

标签: c# exception-handling servicestack

在我正在使用的项目中,使用服务堆栈,下一步是 HandleException ServiceBase类的方法:

    public abstract class BaseAggregationService<TRequest, TResponse> : ServiceBase<TRequest> 
    where TRequest : BaseAggregationRequest 
    where TResponse : BaseAggregationResponse
    {
         ....
         protected override object HandleException(TRequest request, Exception ex)
         {
             base.HandleException(request, ex);

             Logger.Error(request.Metadata, ex);

             var response = (TResponse) Activator.CreateInstance(typeof (TResponse), new Metadata());
             response.Exception = new AggregationException(ex);

             return response;
         }
    }

实现的本机示例(来自github wiki)如下所示。

    public class MyServiceBase<TRequest> : RestService<TRequest>
    {
        public override object HandleException(TRequest request, Exception exception)
        {
           //log your exceptions here
           ...
           //call default exception handler or prepare your own custom response with 
           return base.HandleException(request, exception);
           // or prepare new customer response with new HttpError(...)
        }
    }

我的问题是我无法接收异常字段 - 它总是为null。此方法对响应的其他更改按预期收到。我应该进行任何其他配置还是我没有适当的实现?

0 个答案:

没有答案