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
19 changes: 19 additions & 0 deletions src/Http/Wolverine.Http.Tests/OnExceptionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,23 @@ public async Task middleware_on_exception_handler()
problem.ShouldNotBeNull();
problem!.Title.ShouldBe("Global Error Handler");
}

// PR #3000 regression: an HTTP-endpoint OnException with an *extra* injected parameter
// (the author's literal ILogger example) alongside the exception still resolves the
// parameter and returns its ProblemDetails response.
[Fact]
public async Task on_exception_with_extra_injected_parameter()
{
var result = await Scenario(x =>
{
x.Get.Url("/on-exception/injected-parameter");
x.StatusCodeShouldBe(500);
x.ContentTypeShouldBe("application/problem+json");
});

var problem = await result.ReadAsJsonAsync<Microsoft.AspNetCore.Mvc.ProblemDetails>();
problem.ShouldNotBeNull();
problem!.Title.ShouldBe("Injected Parameter Error");
problem.Detail.ShouldBe("Injected parameter error");
}
}
25 changes: 25 additions & 0 deletions src/Http/WolverineWebApi/OnExceptionEndpoints.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Wolverine.Http;

namespace WolverineWebApi;
Expand Down Expand Up @@ -198,6 +199,30 @@ public static ProblemDetails OnException(Exception ex)

#endregion

// Probe (PR #3000 regression): does an HTTP-endpoint OnException support an *extra*
// injected parameter alongside the exception (the author's literal ILogger example),
// returning a ProblemDetails response?
public static class InjectedParameterExceptionEndpoints
{
[WolverineGet("/on-exception/injected-parameter")]
public static string EndpointThatThrowsForInjection()
{
throw new CustomHttpException("Injected parameter error");
}

public static ProblemDetails OnException(CustomHttpException ex,
ILogger<CustomHttpException> logger)
{
logger.LogError(ex, "Handled in OnException with an injected logger");
return new ProblemDetails
{
Status = 500,
Detail = ex.Message,
Title = "Injected Parameter Error"
};
}
}

#region sample_on_exception_void_return
/// <summary>
/// OnException with void return — exception is still swallowed
Expand Down
Loading
Loading