【发布时间】:2015-10-28 16:54:09
【问题描述】:
public class GlobalExceptionHandler : ExceptionHandler
{
public override void Handle(ExceptionHandlerContext context)
{
context.Result = new NiceInternalServerExceptionResponse("The current operation could not be completed sucessfully.);
}
}
当调用此 Get 操作时:
[HttpGet]
public async Task<IHttpActionResult> Get()
{
Convert.ToInt16("this causes an exception state");
var data = await service.Get();
return Ok(data);
}
引发了异常...并触发了我的全局 exc 处理程序。
当我的自定义响应返回给客户端时,我的提琴手总是说:
结果:200
我也可以将return Ok(data); 更改为return NotFound();
这不会改变结果状态代码中的任何内容。
如何覆盖/拦截 http 状态创建并返回我自己的状态码 500?
在我的网络客户端上,只有在返回状态代码 500 时,我才需要显示一个带有日志记录 ID + 错误消息的漂亮错误对话框。
【问题讨论】:
标签: c# asp.net-web-api asp.net-web-api2