Trying to investigate ProblemDetails and meet some issues.
My code
using Microsoft.AspNetCore.Builder;
using WebApplication3;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddProblemDetails();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var app = builder.Build();
app.UseStatusCodePages();
app.UseExceptionHandler();
app.MapGet("/hello", () =>
{
throw new Exception("Oulah. Hello API has problems!");
});
app.MapGet("/bad", () => Results.BadRequest(new
{
message = "Very bad, you have a problem."
}));
app.Run();
As you can see there are 2 API: hello and bad.
My issue
I get the expected response body with hello:
But with bad it is a different story:
ProblemDetail is not activated.
I can’t see what is different in my code than in other exemples I can see.
What I need
- to understand what is happening
- What I can do
Thank you