blob: 121aee6a99e70d44619e174dcafcff5073e10843 (
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
|
using Microsoft.AspNetCore.Mvc;
using System.Text;
using Timeline.Models.Http;
namespace Timeline.Helpers
{
public static class InvalidModelResponseFactory
{
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(new CommonResponse(ErrorCodes.Common.InvalidModel, $"Request format is bad. {messageBuilder}"));
}
}
}
|