The following post explains exactly how to globally handle validation errors thrown by the ASP .NET core framework.

Centralized exception handling and request validation in ASP.NET Core

 

Validation errors will not trigger the “UseExceptionHandler”.

If you want to change the response for validation errors you will have to configure the “ApiBehaviorOptions”

services.AddMvc()

    .AddJsonOptions(option => option.SerializerSettings.DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Local)

    .SetCompatibilityVersion(CompatibilityVersion.Version_2_2);

 

services.Configure<ApiBehaviorOptions>(options =>

{

    options.InvalidModelStateResponseFactory = ctx => new ValidationProblemDetailsResult(_logger);

<

p style=”background: #1e1e1e”>});

 

 

Read “https://www.strathweb.com/2018/07/centralized-exception-handling-and-request-validation-in-asp-net-core/” for more details.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.