public async Task InvokeAsync(HttpContext context, RequestDelegate next) { try { await next(context); } catch (Exception ex) { context.AddApiErrorHeaders(); context.AddApiErrorStatusCode(ex); await context.Response.WriteAsync(await ex.ToErrorContent(isDevelopment : true).ReadAsStringAsync(), Encoding.UTF8); } }