Backport/pr 42384 to release/7.0 preview7 #42809
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Backport of #42384 to release/7.0-preview4
/cc @brunolins16
Adding ProblemDetailsService
Adding a new
ProblemDetailsService
responsible for consistentProblem Details
generation.Description
API Controllers have a mechanism to auto generated
Problem Details
(https://datatracker.ietf.org/doc/html/rfc7807) for API ControllerActionResult
. The mechanism is enabled by default for allAPI Controllers
, however, it will only generates aProblem Details
payload when theAPI Controller Action
is processed and produces aHTTP Status Code 400+
and noResponse Body
, that means, scenarios like - unhandled exceptions, routing issues - won't produce aProblem Details
payload.Here is overview of when the mechanism will produce the payload:
❌ = Not generated
✅ = Automatically generated
Routing issues: ❌
Unhandled Exceptions: ❌
MVC
StatusCodeResult
400 and up: ✅ (based onSuppressMapClientErrors
)BadRequestResult
andUnprocessableEntityResult
areStatusCodeResult
ProblemDetails
is specified in the input)UnprocessableEntityObjectResult
415 UnsupportedMediaType
: ✅ (Unless when aConsumesAttribute
is defined)406 NotAcceptable
: ❌ (when happens in the output formatter)Minimal APIs
won't generate aProblem Details
payload as well.Here are some examples of reported issues by the community:
This API introduce a new service that is consumed by
Diagnostics Middlewares
to have theProblemDetails
generated, for all Status 400+ and also have a mechanism that allows devs or library authors (eg. API Versioning) generateProblemDetails
responses when opted-in by the users.Sample Usage
Default options
Fixes #42212
Customer Impact
This issue has been reported for years, including a community
middleware
is available to try fix the gap in the framework. This change does not replace the community middleware totally, however, enable the core functionality in the framework.Regression?
Risk
This is a new API. The change to existing code is very small and non-impactful unless the new
AddProblemDetails
method is called.Verification
Packaging changes reviewed?