blob: 71ee44a9df0ef0497bc539e28c2b82425c444571 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
using Microsoft.AspNetCore.Mvc;
using System.Text;
using Timeline.Models.Http;
namespace Timeline.Helpers
{
public static class InvalidModelResponseFactory
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1062:Validate arguments of public methods")]
public static IActionResult Factory(ActionContext context)
{
var modelState = context.ModelState;
var messageBuilder = new StringBuilder();
foreach (var model in modelState)
foreach (var error in model.Value.Errors)
{
messageBuilder.Append(model.Key);
messageBuilder.Append(" : ");
messageBuilder.AppendLine(error.ErrorMessage);
}
return new BadRequestObjectResult(ErrorResponse.Common.CustomMessage_InvalidModel(messageBuilder.ToString()));
}
}
}
|