Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,10 @@ public async Task Invoke(HttpContext context)
context.Response.StatusCode = 500;
}

await _exceptionHandler(new ErrorContext(context, ex));
var errorContext = new ErrorContext(context, ex);

SetExceptionHandlerFeatures(errorContext);
await _exceptionHandler(errorContext);

const string eventName = "Microsoft.AspNetCore.Diagnostics.UnhandledException";
if (_diagnosticSource.IsEnabled(eventName))
Expand Down Expand Up @@ -220,11 +223,6 @@ private async Task DisplayExceptionContent(ErrorContext errorContext)
{
var httpContext = errorContext.HttpContext;

if (_problemDetailsService is not null)
{
SetExceptionHandlerFeatures(errorContext);
}

if (_problemDetailsService == null || !await _problemDetailsService.TryWriteAsync(new()
{
HttpContext = httpContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,51 @@ public async Task Metrics_ExceptionThrown_Unhandled_Reported()
m => AssertRequestException(m, "System.InvalidOperationException", "unhandled"));
}

[Fact]
public async Task ExceptionFeatureSetOnDeveloperExceptionPage()
{
// Arrange
var tcs = new TaskCompletionSource<IExceptionHandlerPathFeature>(TaskCreationOptions.RunContinuationsAsynchronously);

using var host = new HostBuilder()
.ConfigureWebHost(webHostBuilder =>
{
webHostBuilder
.UseTestServer()
.Configure(app =>
{
app.Use(async (context, next) =>
{
await next();

var exceptionHandlerFeature = context.Features.GetRequiredFeature<IExceptionHandlerPathFeature>();
tcs.SetResult(exceptionHandlerFeature);
});
app.UseExceptionHandler(exceptionApp =>
{
exceptionApp.Run(context => Task.CompletedTask);
});
app.Run(context =>
{
throw new Exception("Test exception");
});

});
}).Build();

await host.StartAsync();

var server = host.GetTestServer();
var request = new HttpRequestMessage(HttpMethod.Get, "/path");

var response = await server.CreateClient().SendAsync(request);

var feature = await tcs.Task;
Assert.NotNull(feature);
Assert.Equal("Test exception", feature.Error.Message);
Assert.Equal("/path", feature.Path);
}

[Fact]
public async Task Metrics_ExceptionThrown_ErrorPathHandled_Reported()
{
Expand Down
Loading