private static async Task WriteErrorResponse(this HttpContext context, ILifetimeScope scope, Exception e) { var webContext = scope.Resolver.Resolve <IWebContextProvider>().Get(); if (webContext.IsAjax) { context.Response.ContentType = "text/plain"; } await context.Response.WriteAsync(scope.GenerateErrorResponse(e, webContext.IsAjax)); }