1
如果请求生命周期中的某个位置出现异常,则的响应为null
。在ExceptionFilterAttribute中获取控制器的返回类型 - HttpActionExecutedContext
public class MyExceptionFilterAttribute : ExceptionFilterAttribute
{
public override void OnException(HttpActionExecutedContext httpActionExecutedContext)
{
// Get expected return type here
// Can't be httpActionExecutedContext.Response.GetType() because response is null
}
}
我想要做的是返回相同的期望对象,但与一个对象的字段中创建一个错误。
有没有办法找出预期的响应类型是什么?
是否有理由需要这个?这并不总是可能的。 – DavidG
是的,客户希望返回一个确切的XML结构。这意味着如果客户期待AccountResponse,并发生错误,它将需要没有AccountResponse.Error – kotsumu