Skip to content

Commit

Permalink
[fix] web context is not available on WriteErrorResponseAsync
Browse files Browse the repository at this point in the history
  • Loading branch information
i4004 committed Jun 24, 2024
1 parent 66d5e32 commit f237e68
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/Simplify.Web/Middleware/SimplifyWebRequestMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using Simplify.Web.Diagnostics.Measurements;
using Simplify.Web.Diagnostics.Trace;
using Simplify.Web.Modules;
using Simplify.Web.Modules.Context;
using Simplify.Web.RequestHandling;
using Simplify.Web.Settings;

Expand Down Expand Up @@ -86,12 +85,12 @@ internal static bool ProcessOnException(Exception e)

private static async Task WriteErrorResponseAsync(this HttpContext context, ILifetimeScope scope, Exception e)
{
var webContext = scope.Resolver.Resolve<IWebContextProvider>().Get();
var isAjax = context.Request.Headers.ContainsKey("X-Requested-With");

if (webContext.IsAjax)
if (isAjax)
context.Response.ContentType = "text/plain";

await context.Response.WriteAsync(scope.GenerateErrorResponse(e, webContext.IsAjax));
await context.Response.WriteAsync(scope.GenerateErrorResponse(e, isAjax));
}

private static string GenerateErrorResponse(this ILifetimeScope scope, Exception e, bool minimalStyle)
Expand Down

0 comments on commit f237e68

Please sign in to comment.