为什么发生错误时邮递员会发回200 OK?

问题描述

我已经设置了一些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 (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...