diff --git a/.gitignore b/.gitignore index 0fceb20..0aadb21 100644 --- a/.gitignore +++ b/.gitignore @@ -435,5 +435,5 @@ fabric.properties *.jwk -**/keys -/src/ApiGateway/back.txt +# Monitoring +*.db diff --git a/deployments/docker-compose/monitoring/grafana-data/data/grafana.db b/deployments/docker-compose/monitoring/grafana-data/data/grafana.db index 710a89a..8305069 100644 Binary files a/deployments/docker-compose/monitoring/grafana-data/data/grafana.db and b/deployments/docker-compose/monitoring/grafana-data/data/grafana.db differ diff --git a/src/BuildingBlocks/Exception/ProblemDetailsWithCode.cs b/src/BuildingBlocks/Exception/ProblemDetailsWithCode.cs index 2832cad..b22b881 100644 --- a/src/BuildingBlocks/Exception/ProblemDetailsWithCode.cs +++ b/src/BuildingBlocks/Exception/ProblemDetailsWithCode.cs @@ -3,6 +3,8 @@ using Microsoft.AspNetCore.Mvc; namespace BuildingBlocks.Exception; +using ProblemDetails = Microsoft.AspNetCore.Mvc.ProblemDetails; + public class ProblemDetailsWithCode : ProblemDetails { [JsonPropertyName("code")] diff --git a/src/Services/Flight/src/Flight/Extensions/Infrastructure/ProblemDetailsExtensions.cs b/src/BuildingBlocks/ProblemDetails/Extensions.cs similarity index 97% rename from src/Services/Flight/src/Flight/Extensions/Infrastructure/ProblemDetailsExtensions.cs rename to src/BuildingBlocks/ProblemDetails/Extensions.cs index 0a88a93..870b2b2 100644 --- a/src/Services/Flight/src/Flight/Extensions/Infrastructure/ProblemDetailsExtensions.cs +++ b/src/BuildingBlocks/ProblemDetails/Extensions.cs @@ -1,18 +1,16 @@ -using BuildingBlocks.Exception; -using Microsoft.AspNetCore.Http; -using Microsoft.Extensions.DependencyInjection; - -namespace Flight.Extensions.Infrastructure; +namespace BuildingBlocks.ProblemDetails; +using Exception; using Grpc.Core; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Diagnostics; -using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.WebUtilities; using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; -public static class ProblemDetailsExtensions +public static class Extensions { public static WebApplication UseCustomProblemDetails(this WebApplication app) { @@ -127,3 +125,4 @@ public static class ProblemDetailsExtensions return app; } } + diff --git a/src/Services/Booking/src/Booking/Extensions/Infrastructure/InfrastructureExtensions.cs b/src/Services/Booking/src/Booking/Extensions/Infrastructure/InfrastructureExtensions.cs index 928f3ed..9f9f0a5 100644 --- a/src/Services/Booking/src/Booking/Extensions/Infrastructure/InfrastructureExtensions.cs +++ b/src/Services/Booking/src/Booking/Extensions/Infrastructure/InfrastructureExtensions.cs @@ -24,6 +24,8 @@ using Serilog; namespace Booking.Extensions.Infrastructure; +using BuildingBlocks.ProblemDetails; + public static class InfrastructureExtensions { public static WebApplicationBuilder AddInfrastructure(this WebApplicationBuilder builder) diff --git a/src/Services/Booking/src/Booking/Extensions/Infrastructure/ProblemDetailsExtensions.cs b/src/Services/Booking/src/Booking/Extensions/Infrastructure/ProblemDetailsExtensions.cs deleted file mode 100644 index 46d2d98..0000000 --- a/src/Services/Booking/src/Booking/Extensions/Infrastructure/ProblemDetailsExtensions.cs +++ /dev/null @@ -1,129 +0,0 @@ -namespace Booking.Extensions.Infrastructure; - -using BuildingBlocks.Exception; -using Grpc.Core; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Diagnostics; -using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.WebUtilities; -using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; - -public static class ProblemDetailsExtensions -{ - public static WebApplication UseCustomProblemDetails(this WebApplication app) - { - app.UseStatusCodePages(statusCodeHandlerApp => - { - statusCodeHandlerApp.Run(async context => - { - context.Response.ContentType = "application/problem+json"; - - if (context.RequestServices.GetService() is { } problemDetailsService) - { - await problemDetailsService.WriteAsync(new ProblemDetailsContext - { - HttpContext = context, - ProblemDetails = - { - Detail = ReasonPhrases.GetReasonPhrase(context.Response.StatusCode), - Status = context.Response.StatusCode - } - }); - } - }); - - }); - - app.UseExceptionHandler(exceptionHandlerApp => - { - exceptionHandlerApp.Run(async context => - { - context.Response.ContentType = "application/problem+json"; - - if (context.RequestServices.GetService() is { } problemDetailsService) - { - var exceptionHandlerFeature = context.Features.Get(); - var exceptionType = exceptionHandlerFeature?.Error; - - if (exceptionType is not null) - { - (string Detail, string Title, int StatusCode) details = exceptionType switch - { - ConflictException => - ( - exceptionType.Message, - exceptionType.GetType().Name, - context.Response.StatusCode = StatusCodes.Status409Conflict - ), - ValidationException validationException => - ( - exceptionType.Message, - exceptionType.GetType().Name, - context.Response.StatusCode = (int)validationException.StatusCode - ), - BadRequestException => - ( - exceptionType.Message, - exceptionType.GetType().Name, - context.Response.StatusCode = StatusCodes.Status400BadRequest - ), - NotFoundException => - ( - exceptionType.Message, - exceptionType.GetType().Name, - context.Response.StatusCode = StatusCodes.Status404NotFound - ), - AppException => - ( - exceptionType.Message, - exceptionType.GetType().Name, - context.Response.StatusCode = StatusCodes.Status400BadRequest - ), - DbUpdateConcurrencyException => - ( - exceptionType.Message, - exceptionType.GetType().Name, - context.Response.StatusCode = StatusCodes.Status409Conflict - ), - RpcException => - ( - exceptionType.Message, - exceptionType.GetType().Name, - context.Response.StatusCode = StatusCodes.Status400BadRequest - ), - _ => - ( - exceptionType.Message, - exceptionType.GetType().Name, - context.Response.StatusCode = StatusCodes.Status500InternalServerError - ) - }; - - var problem = new ProblemDetailsContext - { - HttpContext = context, - ProblemDetails = - { - Title = details.Title, - Detail = details.Detail, - Status = details.StatusCode - } - }; - - if (app.Environment.IsDevelopment()) - { - problem.ProblemDetails.Extensions.Add("exception", exceptionHandlerFeature?.Error.ToString()); - } - - await problemDetailsService.WriteAsync(problem); - } - } - }); - }); - - return app; - } -} diff --git a/src/Services/Flight/src/Flight/Extensions/Infrastructure/InfrastructureExtensions.cs b/src/Services/Flight/src/Flight/Extensions/Infrastructure/InfrastructureExtensions.cs index 7890a8e..3ad8409 100644 --- a/src/Services/Flight/src/Flight/Extensions/Infrastructure/InfrastructureExtensions.cs +++ b/src/Services/Flight/src/Flight/Extensions/Infrastructure/InfrastructureExtensions.cs @@ -27,6 +27,8 @@ using Serilog; namespace Flight.Extensions.Infrastructure; +using BuildingBlocks.ProblemDetails; + public static class InfrastructureExtensions { public static WebApplicationBuilder AddInfrastructure(this WebApplicationBuilder builder) diff --git a/src/Services/Identity/src/Identity.Api/keys/is-signing-key-0AC3347A09AA5E44E947F3E30ED54871.json b/src/Services/Identity/src/Identity.Api/keys/is-signing-key-0AC3347A09AA5E44E947F3E30ED54871.json new file mode 100644 index 0000000..86e98ed --- /dev/null +++ b/src/Services/Identity/src/Identity.Api/keys/is-signing-key-0AC3347A09AA5E44E947F3E30ED54871.json @@ -0,0 +1 @@ +{"Version":1,"Id":"0AC3347A09AA5E44E947F3E30ED54871","Created":"2023-02-22T21:06:15.7901014Z","Algorithm":"RS256","IsX509Certificate":false,"Data":"CfDJ8Pno3caweVxDrMdMtoqjLU9W7bGGdPAEm8VDpWIg5fNfBATZdniIo9r5lhBSMZ3OFJya6SlNGIFe9JkbzJBa5fwNa-omLt15Kjlu3QNX4bAWI3V87P70NAfKDKe4xBVF12B3ooXFXKJ2U5QzFBY8U_1tBXkeUTQKfioQ1lTPxIbQtmSyD-uSc5anbDjtqIWhDq1OlujSJpVHRJV9EzRCms4yZdUc506aWg_KrkpVITZyywj1X1cz-SaUGUqy01wJSXgEj70OdVo2DoPIEYTDAlymi40-R2jQsnseFEG3W7XQlYX29joTygtkumnVED2WF9y9Boy80Kj5XN5XZvL1opV-qtxA8aekkp3XuwMJtBmnMeslHK8TyvBl5JjdZwULdYJFo-rGSDEuI4bswDzMWUgv6oAxgqE6e7SQiFlHuLgWHkmEis4-r-EphCl7B_lNOMQViifon6L8t0lUGdPFhFfN5Fo7cj_lZPx5uqymwVUwIEPrEisZtkwsPYZeKuVdSaRnl5xDlU6AgbQvcNe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oUXu49PgvJ_LkqtM5LAngo5f5DVdrzgX1-9I_KtyamJ9ic8nLqVsI5Z9iof9u9cRyDKhwQ4KPpD3uovwGnK7if25F9UaHFLvAJk2iOQjkA1rQyjCIJzi8dqpdw3W_L3Gc2m9Gr7HS1D0ZtWIk8z-TMNtR2PQcmlWiTJ9ZhLyMs67LWnLZri0jchEw4TJ46EAAUHE1hGhbs8xsmtta1yiu9VaZwCjDb5OJwnnl_2tA1ZkCE5Mh9NGSAZSCYLJCSRaCE53KypCYZBtJhR7Jcl1cz0OY9nNNUpzpPrcmCEz1cLw4z2H1OtujncZHDiyKqh57zQOTs--q9Nx8ytyhg7hBYIcqJFP8Gb0xQPjSkN1oO5ScAPIyPNY54VdIR7sk-99995Y-U6pnLQ_1JdIJZRYYnaYa4c5cqQaRE1n_G-L4_g20aBCX65SKkck5bwsAMJL371t4CqCBfPjzFugoNxR37DWicLUd9sJGBUMjj_lhWsk709om6shSJAy4loiz1qViwPi1K5XcFI7oyH735wg8X05Qxe1tby83X9FSd1FlTpVPRe1btEHddVubt9oeaZ0kOiN5BagaEF4wjIiQttnnzBfjKqcpuyd0zMhDTL_CqlmrTE09HH01VSnZ6lVllzCXGYI2hZKJFeOL7quHV4cDSoEVHOBL7SbChhm62iWOVTe2ho8V1NGnGFMmMfeplVWKorv-k2-L0H-K8rtg9d2vUdt-s5bxKkesUjxJhScBVOlFVcX6GdDa0o2R1W6qszC7D-_UILhIEtkQwnEg9SR-dDMulOotrHp5_LrsMCJLCgqGfzrjVymq7vkHbkh-8XIUzopyXgS4yr__N1MT2lI-7sFBG8fTa-GbN","DataProtected":true} \ No newline at end of file diff --git a/src/Services/Identity/src/Identity.Api/keys/is-signing-key-A57781A0405849BDE786A79636460E49.json b/src/Services/Identity/src/Identity.Api/keys/is-signing-key-A57781A0405849BDE786A79636460E49.json new file mode 100644 index 0000000..7d24288 --- /dev/null +++ b/src/Services/Identity/src/Identity.Api/keys/is-signing-key-A57781A0405849BDE786A79636460E49.json @@ -0,0 +1 @@ +{"Version":1,"Id":"A57781A0405849BDE786A79636460E49","Created":"2023-05-11T21:58:42.4707649Z","Algorithm":"RS256","IsX509Certificate":false,"Data":"CfDJ8Hnjqxp4tLpCov-J-Y0BVs7wR0CVu4eqUuKwsY0rf0WJyME4aNzhKfD2Z2K08hK8_8svrjSptVpC1ttyCPtXtPVMsQQRukJef7SjEUNlC-US2KuwQGOLMYIDNHkTHrnXN7GYHoFtZ1SQWdL61GJ43LYCyFY7_L_Sn9SFepnDcT9H3aA9-M3ZjDJNU8_qknPTEUhSjV1i7AMkYnCHHow0ttlYhcQGwXoiuMMI9oqu26yr79i7sG6m_BAK1f1eg_1cBGozNe4yRPHsRk4qCLKgG-JRaNfV8sXHM-3SpEeFx7iUYHLHl7SiQwsqrODIujk7sz_vJaDbiFqwSVxUTDBEBLPpmPULLGKzjGoPrGtpmvgHkghEsHtvXY6aTzWwDLBmOT4ao8IjImv8D3_ub_KgNC5rg5pBzYA-gKAhtE_RznEKP_DVR836v5Xpw7zMVxbYVNwLrJ5-QtD503G5QhywFUHO9pRiL-dtDHJTpSmq5esy-OKBl2QJ12WxfeeMUQ7tIkTSsj0ALMyJS-a7uVUkITxOkXxrBI5rF6OIK8GZwnmsxJK5L3Urbn76EgiFKVoqgyhBRs0GvRl5-WJyc69m3ltuhp1z7hYOh0BYjlecDd9WOqNbFE68BCYUi7O--mSE0Bv94K4eUs81ccSb3lwC0AtPWPWjG31E9cg8Sd-A1gXhAcYuLmeWSoAP2Issoi5blxeafWUadjbjdCtGI_lA1trpg9LpClEDZZt5uJ5DQa5yUVzdz7l-RnlF7C8ReBtM8qBxJYnaCnc4WC7WE5cKMYG6mGJY55o_EAR4urjsxy2Bdjh34cFIIEQwfh-tnex3uBvYFUzoCPp8KJY-eRhUXEjtZzeds51OVeLKkeyFtSVEZsFTCnmc3tTsOAtkpa7sjsU0Xe0sgMG_E1XS8P_BqfIm9RR8rPblmA6JytNt_Gs2f00ND28PAnj_UuLeOaFpl2sip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WXTHep8_3rdSIyTPrLLqErhCur6U69boZlvoCmoYtgbYN7dA1VkdTzdnzU-zSRLRkOY_hsa2gEElHqdtjHHTdt9g3kNhnvBMmgTQcEsAKZFjnwSbC-BogTSYNiZYCUu9eYOmenwlF4X4Yti-bVpMCEn6_6H8dWjumdBb7hgsvm47Sbuna5vAnlfnPKZBgji-38Y5lPE3NRF0ImhrsaURNUFktoNhp2gwFh8R0nLRzoLr3jWF2pBMMbvKGGzEBxOGN0_3nodoSyjFJFyAHgTwNcxB0AeYImM_-mxFtjiCDESqZoZGWtg6MvXmXPnat_uaI-jwl6TFBUChTjWujfil5doh32BtImNFO8VQakhrpTCaVm6yBKH77eF6aCX50iTuVVBuMec3IJZNPdnsc_65R4VGpqLwdscWiJqtmaRt_Umj-eJ","DataProtected":true} \ No newline at end of file diff --git a/src/Services/Identity/src/Identity/Extensions/Infrastructure/InfrastructureExtensions.cs b/src/Services/Identity/src/Identity/Extensions/Infrastructure/InfrastructureExtensions.cs index db0b96e..69415fe 100644 --- a/src/Services/Identity/src/Identity/Extensions/Infrastructure/InfrastructureExtensions.cs +++ b/src/Services/Identity/src/Identity/Extensions/Infrastructure/InfrastructureExtensions.cs @@ -24,7 +24,7 @@ using Serilog; namespace Identity.Extensions.Infrastructure; -using BuildingBlocks.PersistMessageProcessor.Data; +using BuildingBlocks.ProblemDetails; using Configurations; using Microsoft.AspNetCore.HttpOverrides; diff --git a/src/Services/Identity/src/Identity/Extensions/Infrastructure/ProblemDetailsExtensions.cs b/src/Services/Identity/src/Identity/Extensions/Infrastructure/ProblemDetailsExtensions.cs deleted file mode 100644 index 3223542..0000000 --- a/src/Services/Identity/src/Identity/Extensions/Infrastructure/ProblemDetailsExtensions.cs +++ /dev/null @@ -1,129 +0,0 @@ -namespace Identity.Extensions.Infrastructure; - -using BuildingBlocks.Exception; -using Grpc.Core; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Diagnostics; -using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.WebUtilities; -using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; - -public static class ProblemDetailsExtensions -{ - public static WebApplication UseCustomProblemDetails(this WebApplication app) - { - app.UseStatusCodePages(statusCodeHandlerApp => - { - statusCodeHandlerApp.Run(async context => - { - context.Response.ContentType = "application/problem+json"; - - if (context.RequestServices.GetService() is { } problemDetailsService) - { - await problemDetailsService.WriteAsync(new ProblemDetailsContext - { - HttpContext = context, - ProblemDetails = - { - Detail = ReasonPhrases.GetReasonPhrase(context.Response.StatusCode), - Status = context.Response.StatusCode - } - }); - } - }); - - }); - - app.UseExceptionHandler(exceptionHandlerApp => - { - exceptionHandlerApp.Run(async context => - { - context.Response.ContentType = "application/problem+json"; - - if (context.RequestServices.GetService() is { } problemDetailsService) - { - var exceptionHandlerFeature = context.Features.Get(); - var exceptionType = exceptionHandlerFeature?.Error; - - if (exceptionType is not null) - { - (string Detail, string Title, int StatusCode) details = exceptionType switch - { - ConflictException => - ( - exceptionType.Message, - exceptionType.GetType().Name, - context.Response.StatusCode = StatusCodes.Status409Conflict - ), - ValidationException validationException => - ( - exceptionType.Message, - exceptionType.GetType().Name, - context.Response.StatusCode = (int)validationException.StatusCode - ), - BadRequestException => - ( - exceptionType.Message, - exceptionType.GetType().Name, - context.Response.StatusCode = StatusCodes.Status400BadRequest - ), - NotFoundException => - ( - exceptionType.Message, - exceptionType.GetType().Name, - context.Response.StatusCode = StatusCodes.Status404NotFound - ), - AppException => - ( - exceptionType.Message, - exceptionType.GetType().Name, - context.Response.StatusCode = StatusCodes.Status400BadRequest - ), - DbUpdateConcurrencyException => - ( - exceptionType.Message, - exceptionType.GetType().Name, - context.Response.StatusCode = StatusCodes.Status409Conflict - ), - RpcException => - ( - exceptionType.Message, - exceptionType.GetType().Name, - context.Response.StatusCode = StatusCodes.Status400BadRequest - ), - _ => - ( - exceptionType.Message, - exceptionType.GetType().Name, - context.Response.StatusCode = StatusCodes.Status500InternalServerError - ) - }; - - var problem = new ProblemDetailsContext - { - HttpContext = context, - ProblemDetails = - { - Title = details.Title, - Detail = details.Detail, - Status = details.StatusCode - } - }; - - if (app.Environment.IsDevelopment()) - { - problem.ProblemDetails.Extensions.Add("exception", exceptionHandlerFeature?.Error.ToString()); - } - - await problemDetailsService.WriteAsync(problem); - } - } - }); - }); - - return app; - } -} diff --git a/src/Services/Passenger/src/Passenger/Extensions/Infrastructure/InfrastructureExtensions.cs b/src/Services/Passenger/src/Passenger/Extensions/Infrastructure/InfrastructureExtensions.cs index 2a4c7f5..54b89c5 100644 --- a/src/Services/Passenger/src/Passenger/Extensions/Infrastructure/InfrastructureExtensions.cs +++ b/src/Services/Passenger/src/Passenger/Extensions/Infrastructure/InfrastructureExtensions.cs @@ -25,6 +25,8 @@ using Serilog; namespace Passenger.Extensions.Infrastructure; +using BuildingBlocks.ProblemDetails; + public static class InfrastructureExtensions { public static WebApplicationBuilder AddInfrastructure(this WebApplicationBuilder builder) diff --git a/src/Services/Passenger/src/Passenger/Extensions/Infrastructure/ProblemDetailsExtensions.cs b/src/Services/Passenger/src/Passenger/Extensions/Infrastructure/ProblemDetailsExtensions.cs deleted file mode 100644 index a2f7371..0000000 --- a/src/Services/Passenger/src/Passenger/Extensions/Infrastructure/ProblemDetailsExtensions.cs +++ /dev/null @@ -1,129 +0,0 @@ -namespace Passenger.Extensions.Infrastructure; - -using BuildingBlocks.Exception; -using Grpc.Core; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Diagnostics; -using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.WebUtilities; -using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; - -public static class ProblemDetailsExtensions -{ - public static WebApplication UseCustomProblemDetails(this WebApplication app) - { - app.UseStatusCodePages(statusCodeHandlerApp => - { - statusCodeHandlerApp.Run(async context => - { - context.Response.ContentType = "application/problem+json"; - - if (context.RequestServices.GetService() is { } problemDetailsService) - { - await problemDetailsService.WriteAsync(new ProblemDetailsContext - { - HttpContext = context, - ProblemDetails = - { - Detail = ReasonPhrases.GetReasonPhrase(context.Response.StatusCode), - Status = context.Response.StatusCode - } - }); - } - }); - - }); - - app.UseExceptionHandler(exceptionHandlerApp => - { - exceptionHandlerApp.Run(async context => - { - context.Response.ContentType = "application/problem+json"; - - if (context.RequestServices.GetService() is { } problemDetailsService) - { - var exceptionHandlerFeature = context.Features.Get(); - var exceptionType = exceptionHandlerFeature?.Error; - - if (exceptionType is not null) - { - (string Detail, string Title, int StatusCode) details = exceptionType switch - { - ConflictException => - ( - exceptionType.Message, - exceptionType.GetType().Name, - context.Response.StatusCode = StatusCodes.Status409Conflict - ), - ValidationException validationException => - ( - exceptionType.Message, - exceptionType.GetType().Name, - context.Response.StatusCode = (int)validationException.StatusCode - ), - BadRequestException => - ( - exceptionType.Message, - exceptionType.GetType().Name, - context.Response.StatusCode = StatusCodes.Status400BadRequest - ), - NotFoundException => - ( - exceptionType.Message, - exceptionType.GetType().Name, - context.Response.StatusCode = StatusCodes.Status404NotFound - ), - AppException => - ( - exceptionType.Message, - exceptionType.GetType().Name, - context.Response.StatusCode = StatusCodes.Status400BadRequest - ), - DbUpdateConcurrencyException => - ( - exceptionType.Message, - exceptionType.GetType().Name, - context.Response.StatusCode = StatusCodes.Status409Conflict - ), - RpcException => - ( - exceptionType.Message, - exceptionType.GetType().Name, - context.Response.StatusCode = StatusCodes.Status400BadRequest - ), - _ => - ( - exceptionType.Message, - exceptionType.GetType().Name, - context.Response.StatusCode = StatusCodes.Status500InternalServerError - ) - }; - - var problem = new ProblemDetailsContext - { - HttpContext = context, - ProblemDetails = - { - Title = details.Title, - Detail = details.Detail, - Status = details.StatusCode - } - }; - - if (app.Environment.IsDevelopment()) - { - problem.ProblemDetails.Extensions.Add("exception", exceptionHandlerFeature?.Error.ToString()); - } - - await problemDetailsService.WriteAsync(problem); - } - } - }); - }); - - return app; - } -}