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
ProblemDetailsServiceresponsible for consistentProblem Detailsgeneration.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 Detailspayload when theAPI Controller Actionis processed and produces aHTTP Status Code 400+and noResponse Body, that means, scenarios like - unhandled exceptions, routing issues - won't produce aProblem Detailspayload.Here is overview of when the mechanism will produce the payload:
❌ = Not generated
✅ = Automatically generated
Routing issues: ❌
Unhandled Exceptions: ❌
MVC
StatusCodeResult400 and up: ✅ (based onSuppressMapClientErrors)BadRequestResultandUnprocessableEntityResultareStatusCodeResultProblemDetailsis specified in the input)UnprocessableEntityObjectResult415 UnsupportedMediaType: ✅ (Unless when aConsumesAttributeis defined)406 NotAcceptable: ❌ (when happens in the output formatter)Minimal APIswon't generate aProblem Detailspayload as well.Here are some examples of reported issues by the community:
This API introduce a new service that is consumed by
Diagnostics Middlewaresto have theProblemDetailsgenerated, for all Status 400+ and also have a mechanism that allows devs or library authors (eg. API Versioning) generateProblemDetailsresponses when opted-in by the users.Sample Usage
Default options
Fixes #42212
Customer Impact
This issue has been reported for years, including a community
middlewareis 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
AddProblemDetailsmethod is called.Verification
Packaging changes reviewed?