Skip to content

Support more ProblemDetails Titles out-of-the-box #43232

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

martincostello
Copy link
Member

Support more ProblemDetails Titles out-of-the-box

Add support for more default HTTP status titles with problem details.

Description

  • Use ReasonPhrases.GetReasonPhrase() to extend the default titles for problem details.
  • Update relevant links from RFC7231 to RFC9110.
  • Add problem details titles and types for HTTP statuses 408, 412, 426 and 502-504.

Fixes #36417.

- Use `ReasonPhrases.GetReasonPhrase()` to extend the default titles for problem details.
- Apply some minor code clean-ups.
- Update links returned for problem details from RFC7231 to RFC9110.
- Update other references from RFC7231 to RFC9110.
Add titles and types for HTTP 408, 412, 426 and 502-504.
Update remaining references from RFC7231 to RFC9110.
Do not set the problem details title to the empty string when the HTTP status code does not have a default reason phrase and leave it as null.
@ghost ghost added the community-contribution Indicates that the PR has been added by a community member label Aug 12, 2022
@ghost
Copy link

ghost commented Aug 12, 2022

Thanks for your PR, @martincostello. Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@@ -24,6 +24,7 @@

<ItemGroup>
<Reference Include="Microsoft.AspNetCore.Http.Abstractions" />
<Reference Include="Microsoft.AspNetCore.WebUtilities" />
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added as suggested by #36417 (comment)

Fix test by adding the new expected status codes.
Revert over-zealous update to RFC links as HTTP 422 wasn't RFC7231 in the first place.
@Pilchie Pilchie added the old-area-web-frameworks-do-not-use *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels label Aug 12, 2022
"An error occurred while processing your request."
),

[502] =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was hoping to be able to consolidate both lists (ProblemDetailsDefaults.Defaults and ReasonPhrases.Phrases , including the reference URL, to avoid this adding new status codes here. But we probably will need a public API change :(.

@brunolins16
Copy link
Member

  • Add problem details titles and types for HTTP statuses 408, 412, 426 and 502-504.

Is there a reason for this?

@martincostello
Copy link
Member Author

Just some additional statuses that I consider common I thought I'd add as I was touching the code. Happy to remove if they're not wanted.

"https://tools.ietf.org/html/rfc9110#section-15.5.22",
"Upgrade Required"
),

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

429? I think it'll be even more common with rate limiting built into the framework.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to add if the team is happy with the other additions I already made.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see why not add 429 as well.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember why I didn't add it now - it's not in the RFC 😄

@brunolins16
Copy link
Member

Just some additional statuses that I consider common I thought I'd add as I was touching the code. Happy to remove if they're not wanted.

@martincostello Sorry for the delay in reply here. I don't see a problem with that but as I said I was looking for removing all status (consolidating into a single dictionary) here instead adding more. Maybe we can do this for .NET 8.

Copy link
Member

@brunolins16 brunolins16 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM (just some nits) ! @dotnet/minimal-apis anyone else would like to review it?

- Update comment.
- Rename test.
- Refactor code style.

Co-authored-by: Bruno Oliveira <[email protected]>
@brunolins16 brunolins16 merged commit 77c461e into dotnet:main Aug 26, 2022
@ghost ghost added this to the 8.0-alpha1 milestone Aug 26, 2022
@brunolins16
Copy link
Member

@martincostello Thanks again for the contribution!

@ghost
Copy link

ghost commented Aug 26, 2022

Hi @brunolins16. It looks like you just commented on a closed PR. The team will most probably miss it. If you'd like to bring something important up to their attention, consider filing a new issue and add enough details to build context.

@martincostello martincostello deleted the 36417-more-money-more-problem-details branch August 26, 2022 21:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community-contribution Indicates that the PR has been added by a community member old-area-web-frameworks-do-not-use *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support more ProblemDetails Titles out-of-the-box for Results.Problem()
4 participants