fix 确保null异常和write response问题
This commit is contained in:
@@ -17,21 +17,22 @@ public class IgnoreDataCaseAttribute : Attribute, IAsyncResultFilter
|
||||
var type = result.Value?.GetType();
|
||||
if (type.IsGenericType && type.IsAssignableTo(typeof(IApiResult)))
|
||||
{
|
||||
var apiResult = result.Value as DefaultApiResult<object>;
|
||||
|
||||
var body = new
|
||||
if (result.Value is DefaultApiResult<object> apiResult && !context.HttpContext.Response.HasStarted)
|
||||
{
|
||||
code = 200,
|
||||
msg = "操作成功",
|
||||
data = apiResult.Data
|
||||
};
|
||||
var body = new
|
||||
{
|
||||
code = 200,
|
||||
msg = "操作成功",
|
||||
data = apiResult.Data
|
||||
};
|
||||
|
||||
var json = JsonConvert.SerializeObject(body);
|
||||
var bytes = Encoding.UTF8.GetBytes(json);
|
||||
var json = JsonConvert.SerializeObject(body);
|
||||
var bytes = Encoding.UTF8.GetBytes(json);
|
||||
|
||||
context.HttpContext.Response.ContentType = "application/json";
|
||||
context.HttpContext.Response.ContentLength = bytes.Length;
|
||||
await context.HttpContext.Response.BodyWriter.WriteAsync(bytes);
|
||||
context.HttpContext.Response.ContentType = "application/json";
|
||||
context.HttpContext.Response.ContentLength = bytes.Length;
|
||||
await context.HttpContext.Response.BodyWriter.WriteAsync(bytes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user