Outline

Demo: Change Model Validation Error Response

In Conduilt.Api Project
  • Modify Startup.cs, ConfigureService method
  • Order in which the code is processed matters
  • Put the code after AddControllers()
            services.Configure<ApiBehaviorOptions>(options =>
            {
                    options.InvalidModelStateResponseFactory = context =>
                    {
                            var errors = new SerializableError(context.ModelState);
                            var result = new UnprocessableEntityObjectResult(new { errors });
                            return result;
                    };
            });

Conduit Github Repo

Tag Name: modify-model-validation-behavior