ylliX - Online Advertising Network
How to build GenAI mock server?

I can’t make ProblemDetails pattern working every time


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:

enter image description here

But with bad it is a different story:

enter image description here

ProblemDetail is not activated.

I can’t see what is different in my code than in other exemples I can see.

What I need

  1. to understand what is happening
  2. What I can do

Thank you



Source link

Leave a Reply

Your email address will not be published. Required fields are marked *