diff options
| author | transtrike <transtrike@gmail.com> | 2021-04-08 14:20:37 +0300 |
|---|---|---|
| committer | transtrike <transtrike@gmail.com> | 2021-04-08 14:20:37 +0300 |
| commit | ea4dafaf8f41cbcce19fa4d872d9ed22590db7d5 (patch) | |
| tree | bf40be440007a20261b436c9f7259fa244848f65 /src/Web/DevHive.Web/Configurations | |
| parent | ffc6b7cd6e454627c95044e88037b37d31dcfce3 (diff) | |
| download | DevHive-ea4dafaf8f41cbcce19fa4d872d9ed22590db7d5.tar DevHive-ea4dafaf8f41cbcce19fa4d872d9ed22590db7d5.tar.gz DevHive-ea4dafaf8f41cbcce19fa4d872d9ed22590db7d5.zip | |
Improved parsing of errors from Attributes. Reverted old style of errors
shown
Diffstat (limited to 'src/Web/DevHive.Web/Configurations')
| -rw-r--r-- | src/Web/DevHive.Web/Configurations/Extensions/ConfigureExceptionHandlerMiddleware.cs | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/Web/DevHive.Web/Configurations/Extensions/ConfigureExceptionHandlerMiddleware.cs b/src/Web/DevHive.Web/Configurations/Extensions/ConfigureExceptionHandlerMiddleware.cs index c017a8c..6885f84 100644 --- a/src/Web/DevHive.Web/Configurations/Extensions/ConfigureExceptionHandlerMiddleware.cs +++ b/src/Web/DevHive.Web/Configurations/Extensions/ConfigureExceptionHandlerMiddleware.cs @@ -1,11 +1,33 @@ using DevHive.Web.Middleware; using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Configuration; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Http; namespace DevHive.Web.Configurations.Extensions { public static class ConfigureExceptionHandlerMiddleware { + public static void ConfigureExceptionHandler(this IServiceCollection services, IConfiguration configuration) + { + services.Configure<ApiBehaviorOptions>(o => + { + o.InvalidModelStateResponseFactory = actionContext => + { + var problemDetails = new ValidationProblemDetails(actionContext.ModelState) + { + Status = StatusCodes.Status422UnprocessableEntity + }; + + return new UnprocessableEntityObjectResult(problemDetails) + { + ContentTypes = { "application/problem+json" } + }; + }; + }); + } + public static void UseExceptionHandlerMiddlewareConfiguration(this IApplicationBuilder app) { app.UseMiddleware<ExceptionMiddleware>(); |
