Merge pull request #22600 from dotnet/safia/problem-details

Add docs on generating ProblemDetails payload
pull/22625/head
Safia Abdalla 2021-06-27 11:45:25 -07:00 committed by GitHub
commit 4c448c256f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 0 deletions

View File

@ -329,3 +329,8 @@ Use the <xref:Microsoft.AspNetCore.Mvc.ApiBehaviorOptions.ClientErrorMapping%2A>
## Custom Middleware to handle exceptions
The defaults in the exception handling middleware works well for most apps. For apps that require specialized exception handling, consider [customizing the exception handling middleware](xref:fundamentals/error-handling#exception-handler-lambda).
### Producing a ProblemDetails payload for exceptions
ASP.NET Core doesn't produce a standardized error payload when the server encounters an unhandled exception. For scenarios where it is desireable to return a standardized [ProblemDetails response](https://datatracker.ietf.org/doc/html/rfc7807) to the client, the [ProblemDetails middleware](https://www.nuget.org/packages/Hellang.Middleware.ProblemDetails/) can be used to map exceptions and 404s to a [ProblemDetails](xref:web-api/handle-errors#pd) payload. The exception handling middleware can also be used to return a <xref:Microsoft.AspNetCore.Mvc.ProblemDetails> payload for unhandled exceptions.