mirror of
https://github.com/aspnet/JavaScriptServices.git
synced 2026-02-07 16:44:17 +00:00
Move from ValidationErrorResult to HttpBadRequest, and support object-level errors too
This commit is contained in:
@@ -1,30 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.AspNet.Mvc;
|
||||
using Microsoft.AspNet.Mvc.ModelBinding;
|
||||
|
||||
namespace Microsoft.AspNet.SpaServices
|
||||
{
|
||||
public class ValidationErrorResult : ObjectResult {
|
||||
public const int DefaultStatusCode = 400;
|
||||
|
||||
public ValidationErrorResult(ModelStateDictionary modelState, int errorStatusCode = DefaultStatusCode)
|
||||
: base(CreateResultObject(modelState))
|
||||
{
|
||||
if (!modelState.IsValid) {
|
||||
this.StatusCode = errorStatusCode;
|
||||
}
|
||||
}
|
||||
|
||||
private static IDictionary<string, IEnumerable<string>> CreateResultObject(ModelStateDictionary modelState)
|
||||
{
|
||||
if (modelState.IsValid) {
|
||||
return null;
|
||||
} else {
|
||||
return modelState
|
||||
.Where(m => m.Value.Errors.Any())
|
||||
.ToDictionary(m => m.Key, m => m.Value.Errors.Select(me => me.ErrorMessage));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user