[Docs] Purpose of ProblemDetails library
See original GitHub issueI’ve seen various mentions of Hellang.Middleware.ProblemDetails
and I’m trying to figure out what it does. Regrettably, the readme and sample code don’t explain.
I suspect it catches unhandled exceptions and converts them to ProblemDetails
. However that’s something that can be done in an exception middleware/filter/handler/whatever. Since this library seems really “fancy”, I’m sure it does more than just that! 😃
Can someone please tell me what this library actually “does”? Thanks!
(BTW: I’m not trolling, I really want to know. The Microsoft docs site even recommends this library.)
Issue Analytics
- State:
- Created 2 years ago
- Comments:16 (12 by maintainers)
Top Results From Across the Web
ProblemDetails Class (Microsoft.AspNetCore.Mvc)
A short, human-readable summary of the problem type. It SHOULD NOT change from occurrence to occurrence of the problem, except for purposes of...
Read more >Using the ProblemDetails Class in ASP.NET Core Web API
ProblemDetails class in ASP.NET Core Web APIs helps us to standardize our error handling and have better communication with API clients.
Read more >Problem Details in .Net 7 - Meysam Hadeli's Blog
Problem Detail provide machine-readable details of errors in a HTTP response to avoid the need to define new error response formats for HTTP ......
Read more >ProblemDetail (Spring Framework 6.0.11 API)
Representation for an RFC 7807 problem detail. Includes spec-defined properties, and a properties map for additional, non-standard properties.
Read more >RFC 7807 - Problem Details for HTTP APIs
The data model for problem details is a JSON [RFC7159] object; when formatted as a JSON document, it uses the "application/problem+json" media type....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Yeah, I think that matches what I would expect 👍
Regarding the 422 status code; it’s an opinion of mine that syntactically correct, but semantically invalid requests should return back a different status code than 400 Bad Request:
From RFC 7231:
It’s increasingly common to use 422 Unprocessable Entity for this 😃
From RFC 4918:
Some people don’t like it (often because it’s part of the WebDAV RFC and not an “official” HTTP RFC (but this will soon change, with the inclusion of 422 in HTTPbis’ upcoming HTTP Semantics RFC, which obsoletes RFC 7231), so I’ve added an option to change it:
https://github.com/khellang/Middleware/blob/eb7f59cb5aaff0727466622af6230db12703a32f/src/ProblemDetails/ProblemDetailsOptions.cs#L133-L136
Some more info about
AddProblemDetailsConventions
, based on khellang’s comments here:ProblemDetailsFactory
to use the middleware’s configuration instead. This will give you more consistent errors, no matter where they are produced. I.e. from MVC’s invalid state filter etc.ProblemDetails
instances from controllers a bit more consistent, by calling the middleware hooks