In consistency in ProblemDetails and ValidationProblemDetails implementation
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 290
Description
### Is there an existing issue for this?
- [X] I have searched the existing issues
### Describe the bug
Hi,
Please have a look at below responses after enabling problems details middle-wear in .NET 7.
- For validation error (Was already existing in .NET previous versions too)
```json
{
"type": "https://tools.ietf.org/html/rfc9110#section-15.5.1",
"title": "One or more validation errors occurred.",
"status": 400,
"errors": {
"weatherForecast": [
"The weatherForecast field is required."
],
"$.date": [
"The JSON value could not be converted to System.DateOnly. Path: $.date | LineNumber: 1 | BytePositionInLine: 11."
]
},
"traceId": "00-bbafef192204f0c436a41ca4eb806680-d41fefd8ce30a3a6-00"
}
```
- For internal server error. Added in .NET 7
```json
{
"type": "https://tools.ietf.org/html/rfc9110#section-15.6.1",
"title": "System.Exception",
"status": 500,
"detail": "The number is less than or equal to 0!",
"traceId": "00-f3ecb67ebaea65f7d2c72f4fc6e1f1ea-47290b0b93b842b4-00",
"exception": {
"details": "System.Exception: The number is less than or equal to 0!\r\n at ........",
"headers": {
"Accept": [
"*/*"
],
"Connection": [
"keep-alive"
]
},
"path": "/WeatherForecast",
"endpoint": "Handling.Controllers.WeatherForecastController.GetXY (Handling)",
"routeValues": {
"action": "Get",
"controller": "WeatherForecast"
}
}
}
```
https://datatracker.ietf.org/doc/html/rfc7807
- Based on this `specification page`, what I understood I can say that `details` property is `optional`.
- In that sense as a consumer I should mostly relay on the `title` property to pick error message for users.
- But see the `title` in second response `System.Exception`. I can't show that for the users right. It could have been more human readable format like "Internal error has occurred." or "Something went wrong. Please contact administrator." etc.
1. Now I can look at property **errors** and **exceptions** as `extensions` according to the `specification` defines though for both details property can be used. Still, I all ok with this setup.
2. But now as a API consumer I will have details in one response and other does not have so I will pick title to so it for users and log rest of it. But with this "System.Exception" as title it does not look great from user's side. Can this be fixed to make the consumers life a bit easier so that they can stick to `title` as go to error message.
3. Can we have just details without these extensions to also make API consumers life easier to parse the json to class objects? I can raise a different idea chat if needed. But wanted to know if even this is possible.
### Expected Behavior
1. Atleast the title property should have content in "non-tech human" understandable format.
2. Using details instead of extensions, please decide if its easy to implement.
### Steps To Reproduce
_No response_
### Exceptions (if any)
_No response_
### .NET Version
7
### Anything else?
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.