Когда кто-то отправляет неверный json в мою конечную точку (например, вместо этого передает строку типа, если int), мой API отображает исключение сериализации json< /p>
Код: Выделить всё
{
"type": "https://tools.ietf.org/html/rfc9110#section-15.5.1",
"title": "One or more validation errors occurred.",
"status": 400,
"errors": {
"$.questions[0].answers": [
"The JSON value could not be converted to TestingService.Business.Features.V1.Test.Models.Answer[]. Path: $.questions[0].answers | LineNumber: 11 | BytePositionInLine: 20."
]
},
"traceId": "00-690e01e0fb451eed8afa4530616fa13f-0396f3a592bd1518-00"
}
Код: Выделить всё
t do this, becouse the exception throws before this pipline. When I use Midleware - I canНастройка моих контроллеров:
Код: Выделить всё
services.AddControllers(options =>
options.Filters.Add(new ApiErrorFilter()))
.AddJsonOptions(options =>
{
options.JsonSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;
options.JsonSerializerOptions.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull;
options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter());
options.JsonSerializerOptions.Converters.Add(new Core.Infrastructure.DateTimeConverter());
});
Подробнее здесь: https://stackoverflow.com/questions/792 ... re-pipline
Мобильная версия