问题描述
我已经设置了一些customException以在出现错误时返回:
private static Task HandleExceptionAsync(HttpContext context,Exception ex)
{
var error = HttpStatusCode.InternalServerError; // 500 if unexpected
if (ex is NotImplementedException) error = HttpStatusCode.NotImplemented;
else if (ex is UnauthorizedAccessException) error = HttpStatusCode.Unauthorized;
else if (ex is ArgumentException) error = HttpStatusCode.BadRequest;
else if (ex is ArgumentNullException) error = HttpStatusCode.InternalServerError;
var er = new ErrorResponse { error = new Dictionary<string,string> { { "message",ex.Message },{ "StatusCode",error.ToString() } } };
var result = JsonConvert.SerializeObject(er);
//Log to database
Log.Error(ex,result);
context.Response.ContentType = "application/json";
return context.Response.WriteAsync(result);
}
因此,当我从邮递员发出邮递呼叫时,它返回正确的错误消息,但邮递员上显示的状态代码为200“确定”?可能是什么原因?
如果需要,我可以提供有关控制器中内容的更多信息。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)