🚀 feat(新增): 表单验证整合返回格式
This commit is contained in:
parent
f00cd37feb
commit
86e879b288
|
@ -2,7 +2,19 @@
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="GitCommitMessageStorage">
|
<component name="GitCommitMessageStorage">
|
||||||
<option name="messageStorage">
|
<option name="messageStorage">
|
||||||
<MessageStorage />
|
<MessageStorage>
|
||||||
|
<option name="commitTemplate">
|
||||||
|
<CommitTemplate>
|
||||||
|
<option name="body" value="" />
|
||||||
|
<option name="changes" value="" />
|
||||||
|
<option name="closes" value="" />
|
||||||
|
<option name="scope" value="" />
|
||||||
|
<option name="skipCi" value="" />
|
||||||
|
<option name="subject" value="" />
|
||||||
|
<option name="type" value="feat" />
|
||||||
|
</CommitTemplate>
|
||||||
|
</option>
|
||||||
|
</MessageStorage>
|
||||||
</option>
|
</option>
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
|
@ -2,7 +2,6 @@
|
||||||
using Bunny.Dao.Model.Result;
|
using Bunny.Dao.Model.Result;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.AspNetCore.Mvc.Filters;
|
using Microsoft.AspNetCore.Mvc.Filters;
|
||||||
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
|
||||||
|
|
||||||
namespace Bunny.Common.Filter;
|
namespace Bunny.Common.Filter;
|
||||||
|
|
||||||
|
@ -16,9 +15,11 @@ public class ValidateModelStateAttribute : ActionFilterAttribute
|
||||||
if (actionContext.ModelState.IsValid) return;
|
if (actionContext.ModelState.IsValid) return;
|
||||||
|
|
||||||
// 表单验证失败
|
// 表单验证失败
|
||||||
var errorMessage = actionContext.ModelState.Values.First().Errors.First().ErrorMessage;
|
var errorMessage = string.Join(",", actionContext.ModelState.Values
|
||||||
var result =
|
.SelectMany(value => value.Errors)
|
||||||
Result<ModelStateDictionary>.Error(HttpStatusCode.BadRequest, actionContext.ModelState, errorMessage);
|
.Select(value => value.ErrorMessage));
|
||||||
|
|
||||||
|
var result = Result<string>.Error(HttpStatusCode.BadRequest, errorMessage);
|
||||||
|
|
||||||
// 重新复写返回结果
|
// 重新复写返回结果
|
||||||
actionContext.Result = new ObjectResult(result);
|
actionContext.Result = new ObjectResult(result);
|
||||||
|
|
Loading…
Reference in New Issue