调整代码
This commit is contained in:
@@ -15,18 +15,13 @@ namespace NX.ERP.WebAPi.Filters
|
||||
base.OnActionExecuted(actionExecutedContext);
|
||||
if (actionExecutedContext.Exception == null)
|
||||
{
|
||||
ResultModel<object> result = new ResultModel<object>();
|
||||
// 取得由 API 返回的状态代码
|
||||
result.ErrCode = 0;
|
||||
// 取得由 API 返回的资料
|
||||
result.Data = actionExecutedContext.ActionContext.Response.Content.ReadAsAsync<object>().Result;
|
||||
|
||||
//请求是否成功
|
||||
//result.IsSuccess = actionExecutedContext.ActionContext.Response.IsSuccessStatusCode;
|
||||
//结果转为自定义消息格式
|
||||
ResultModel<object> result = new ResultModel<object>
|
||||
{
|
||||
ErrCode = 0,
|
||||
Data = actionExecutedContext.ActionContext.Response.Content.ReadAsAsync<object>().Result
|
||||
};
|
||||
actionExecutedContext.Response.Content = new ObjectContent<ResultModel<object>>(result, GlobalConfiguration.Configuration.Formatters.JsonFormatter);
|
||||
// 重新封装回传格式
|
||||
// actionExecutedContext.Response = httpResponseMessage;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,11 +16,12 @@ namespace NX.ERP.WebAPi.Filters
|
||||
public Task ExecuteExceptionFilterAsync(HttpActionExecutedContext actionExecutedContext, CancellationToken cancellationToken)
|
||||
{
|
||||
var ex = actionExecutedContext.Exception;
|
||||
actionExecutedContext.Response = new System.Net.Http.HttpResponseMessage();
|
||||
|
||||
actionExecutedContext.Response.Content = new System.Net.Http.ObjectContent(typeof(ResultModel),
|
||||
actionExecutedContext.Response = new System.Net.Http.HttpResponseMessage
|
||||
{
|
||||
Content = new System.Net.Http.ObjectContent(typeof(ResultModel),
|
||||
new ResultModel { ErrCode = 500, ErrMsg = ex.Message },
|
||||
GlobalConfiguration.Configuration.Formatters.JsonFormatter);
|
||||
GlobalConfiguration.Configuration.Formatters.JsonFormatter)
|
||||
};
|
||||
|
||||
return Task.FromResult(0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user