/// <summary> /// Invokes the middleware /// </summary> public async Task Invoke(HttpContext context) { try { await _next.Invoke(context); } catch (Exception ex) { context.Response.ContentType = "application/json"; context.Response.StatusCode = (int)_httpStatusCodeResolver.Invoke(ex); var response = _errorResponseFactory.Invoke(ex); var responseJson = JsonConvert.SerializeObject(response); await context.Response.WriteAsync(responseJson); } }