【发布时间】:2015-06-14 05:57:39
【问题描述】:
我正在使用 Web API 并实现委托处理程序。
我有一个自定义的 Json 序列化器/反序列化器,它在 API 配置中注册为格式化程序。
var globalFormatters = GlobalConfiguration.Configuration.Formatters;
var jsonFormatter = globalFormatters.JsonFormatter;
jsonFormatter.SerializerSettings.Formatting = Newtonsoft.Json.Formatting.Indented;
jsonFormatter.SerializerSettings.Converters.Add(...)
关于异常处理,我已经添加了一个ExceptionFilterAttribute,并且在配置中也添加了它作为过滤器。
public class MethodAttributeExceptionHandling : ExceptionFilterAttribute
{
public override void OnException(HttpActionExecutedContext actionExecutedContext)
{
var errorHandler = new ErrorHandler();
var response = errorHandler.ProcessError(actionExecutedContext);
actionExecutedContext.Response = response;
}
}
这似乎运行良好,直到我遇到反序列化异常, 没有被我的过滤器捕获。
我已经阅读了异常处理文档Here,其中提到了过滤器没有捕获到序列化异常(但是它没有提到序列化),我找不到任何解决方案来捕获它并正确处理它。
【问题讨论】:
标签: c# .net exception-handling asp.net-web-api