-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Closed
Labels
area-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcfeature-problem-details
Description
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
I'm trying to add raw exception into problem response in CustomizeProblemDetails in dev environment, however, context.Exception is always null.
Expected Behavior
Exception should not be null.
Steps To Reproduce
builder.Services
.AddProblemDetails()
.AddExceptionHandler(options =>
{
options.StatusCodeSelector = exception => exception switch
{
FailedToAuthenticateTokenException _ => StatusCodes.Status401Unauthorized,
_ => (int) HttpStatusCode.InternalServerError
};
});
builder.Services.Configure<ProblemDetailsOptions>(options =>
{
var dumpException = builder.Environment.IsDevelopment();
options.CustomizeProblemDetails = context =>
{
var exception = context.Exception;
if (exception is not null)
{
if (dumpException)
{
context.ProblemDetails.Extensions["exception"] = exception.ToString();
}
}
};
});
var app = builder.Build();
app.UseExceptionHandler();
Exceptions (if any)
No response
.NET Version
9.0.305
Anything else?
Exception handler actually adds exception to problem details. However, DefaultApiProblemDetailsWriter then re-creates problem details and ignores exception which was in original data.
PaulusParssinen
Metadata
Metadata
Assignees
Labels
area-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcfeature-problem-details