给定这样的异常过滤器。
public override void OnException(HttpActionExecutedContext context)
{
var resp = new HttpResponseMessage(HttpStatusCode.InternalServerError)
{
// what must I change here to return an object
// similar to the default exception handler?
Content = new StringContent("THIS IS MY ERROR"),
};
throw new HttpResponseException(resp);
}
返回给客户端 javascript的异常原因是一个纯字符串。
当在默认 WebApi2
控制器中抛出异常时,返回的默认原因对象包含配置、数据、标头等。我找不到如何从我的异常过滤器返回所有这些额外信息的示例。我尝试检查源无济于事...
$http.get('/mydata')
.catch(function(reason) { ... do stuff with reason })
.then(...);
我需要更改什么才能返回相同的默认响应,而不仅仅是一个纯字符串。
Content = new ... // what goes here.