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