RequestDelegateFactory should throw BadHttpRequestException when in development to make diagnosing handler issues easier #35858
Labels
api-approved
API was approved in API review, it can be implemented
area-minimal
Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc
enhancement
This issue represents an ask for new feature or an enhancement to an existing one
feature-minimal-actions
Controller-like actions for endpoint routing
old-area-web-frameworks-do-not-use
*DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels
Priority:1
Work that is critical for the release, but we could probably ship without
Milestone
When using the new "Map*" methods to build minimal APIs via the
RouteDelegateFactory
, it can be difficult to diagnose the cause of 400 and 415 responses that are implicitly returned when the mapped route handler's parameters cannot be satisfied from the request, either via the implicit parameter binding behavior orTryParse' and 'BindAsync
methods on the parameter target types.It would be helpful if when in development (i.e.
Environment.IsDevelopment() == true
) instead of implicitly returning the response with a 4xx status code, aBadHttpRequestException
was thrown instead, with the relevant status code set and an appropriate exception message added, making it clear why the exception/status code is being throw/set. With theDeveloperExceptionPageMiddleware
on (which it is by default in development in .NET 6 when usingWebApplication
) the exception message and stack trace will be returned in the response body, making it much clearer why the invocation of the route handler failed.This behavior should be controllable via a new options type
RouteHandlerOptions
with boolean propertyThrowOnBadRequest
that is configured by default to betrue
whenEnvironment.IsDevelopmet()
is true. The default configuration would be achieved via an internal type implementingIConfigureOptions<RouteHandlerOptions>
that is registered in DI whenIServiceCollection.AddRouting()
is called.Related:
Proposed APIs
Example usage
The text was updated successfully, but these errors were encountered: