using System.Net; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Diagnostics; using Microsoft.AspNetCore.Http; namespace RdtClient.Service.Middleware; public static class ExceptionMiddlewareExtensions { public static void ConfigureExceptionHandler(this IApplicationBuilder app) { app.UseExceptionHandler(appError => { appError.Run(async context => { context.Response.StatusCode = (Int32) HttpStatusCode.InternalServerError; context.Response.ContentType = "application/json"; var contextFeature = context.Features.Get(); if (contextFeature != null) { await context.Response.WriteAsync(contextFeature.Error.Message); } }); }); } }