Skip to content

Commit 70220dc

Browse files
committed
[fix] skip error page write when response has already started in SimplifyWebRequestMiddleware
1 parent 4eb209d commit 70220dc

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

src/Simplify.Web/Middleware/SimplifyWebRequestMiddleware.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,22 @@ await scope.StartMeasurements()
5858
{
5959
try
6060
{
61-
context.Response.StatusCode = 500;
62-
6361
ProcessOnException(e);
6462
}
6563
catch (Exception exception)
6664
{
6765
e = exception;
6866
}
6967

68+
// Once the response has started the headers are already sent — we can neither set the
69+
// status code nor write a clean error page. Rethrow so the original exception surfaces
70+
// with its stack trace instead of being masked by a secondary "response has already
71+
// started" error, and to avoid appending the error page onto a partially-sent body.
72+
if (context.Response.HasStarted)
73+
throw;
74+
75+
context.Response.StatusCode = 500;
76+
7077
await context.WriteErrorResponseAsync(scope, e);
7178
}
7279
}

0 commit comments

Comments
 (0)