How to get HttpValidationProblemDetails response when setting RouteHandlerOptions.ThrowOnBadRequest to false? #53265
Unanswered
paulomorgado
asked this question in
Q&A
Replies: 1 comment
-
There seems to be no way of doing that. I'm doing this: services.ConfigureOptions<RouteHandlerOptionsThrowOnBadRequestPostConfigureOptions>();
// ...
private sealed class RouteHandlerOptionsThrowOnBadRequestPostConfigureOptions : IPostConfigureOptions<RouteHandlerOptions>
{
public void PostConfigure(string? name, RouteHandlerOptions options)
{
options.ThrowOnBadRequest = true;
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
[ASP.NET Core 8.0 Minimal APIs - OpenAPI]
When an API parameter fails to deserialize, by default, it produces a 500 response with
ProblemDetails
if set up for that.If
RouteHandlerOptions.ThrowOnBadRequest
is set tofalse
, the response will be empty with a 400 status code.However, if when setting up an API with
ProducesValidationProblem
, the API is decorated with a required response type ofHttpValidationProblemDetails
.Is there any configuration that can be made to produce
HttpValidationProblemDetails
when aBadHttpRequestException
is thrown?Or is the only option to create an exception handler (
IExceptionHandler
) to handle this kind of exceptions?Beta Was this translation helpful? Give feedback.
All reactions