File tree Expand file tree Collapse file tree 1 file changed +11
-6
lines changed
Expand file tree Collapse file tree 1 file changed +11
-6
lines changed Original file line number Diff line number Diff line change @@ -23,11 +23,16 @@ public class ModelValidationBadRequest
2323{
2424 public static BadRequestObjectResult ModelValidationErrorResponse ( ActionContext actionContext )
2525 {
26- return new BadRequestObjectResult ( actionContext . ModelState
27- . Where ( modelError => modelError . Value . Errors . Any ( ) )
28- . Select ( modelError => new BaseResponse ( ResponseStatus . Error )
29- {
30- Message = modelError . Value . Errors . FirstOrDefault ( ) . ErrorMessage
31- } ) . FirstOrDefault ( ) ) ;
26+ string ? firstError = actionContext . ModelState
27+ . Where ( ms => ms . Value != null && ms . Value . Errors . Any ( ) )
28+ . Select ( ms => ms . Value ! . Errors . FirstOrDefault ( ) ? . ErrorMessage )
29+ . FirstOrDefault ( msg => ! string . IsNullOrWhiteSpace ( msg ) ) ;
30+
31+ BaseResponse response = new BaseResponse ( ResponseStatus . Error )
32+ {
33+ Message = firstError ?? "Validation failed"
34+ } ;
35+
36+ return new BadRequestObjectResult ( response ) ;
3237 }
3338}
You can’t perform that action at this time.
0 commit comments