dotnet / AspNetCore.Docs

Documentation for ASP.NET Core
https://docs.microsoft.com/aspnet/core
Creative Commons Attribution 4.0 International
12.63k stars 25.29k forks source link

ASP.NET Core 2.1 MVC does not transform to ProblemDetails #15670

Closed KalleOlaviNiemitalo closed 4 years ago

KalleOlaviNiemitalo commented 5 years ago

This text appears even when ASP.NET Core 2.1 is selected as the version:

Client error response

An error result is defined as a result with an HTTP status code of 400 or higher. For web API controllers, MVC transforms an error result to a result with ProblemDetails.

However, although ASP.NET Core 2.1.12 defines the ProblemDetail type, it never transforms error results to ProblemDetails. That feature was added for ASP.NET Core 2.2, in https://github.com/aspnet/AspNetCore/commit/5bd818bd64641208e52e9350f443d1336f544e41. Please hide the text when ASP.NET Core 2.1 is selected.


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

KalleOlaviNiemitalo commented 5 years ago

ASP.NET Core 2.1 also suffers from https://github.com/aspnet/Mvc/issues/8501, https://github.com/aspnet/Mvc/issues/8467, and https://github.com/aspnet/Mvc/issues/8317, which make it more difficult to return RFC 7807 compliant responses. The ErrorController sample code in the "Exception handler" section will thus respond with an incorrect Content-Type when running on ASP.NET Core 2.1.

I think this page should do one of:

Rick-Anderson commented 5 years ago

@KalleOlaviNiemitalo is https://github.com/aspnet/AspNetCore.Docs/pull/14366/files correct? I could restore that for the 2.1 version.

KalleOlaviNiemitalo commented 5 years ago

@Rick-Anderson Are you proposing to restore https://github.com/aspnet/AspNetCore.Docs/blob/af85507ca3a3dfbea695082c39457684927f1696/aspnetcore/web-api/handle-errors.md for ASP.NET Core 2.1? It does not seem correct to me. Outside of ::: moniker sections, it:

Rick-Anderson commented 5 years ago

I was hoping that was a valid version for 2.1 We could look at previous versions - there should be correct 2.1 information in a previous version - unless it was never updated for 2.1

KalleOlaviNiemitalo commented 5 years ago

The file was renamed in that pull request. The history of earlier versions is at https://github.com/aspnet/AspNetCore.Docs/commits/d667d2a7ef96b52e07ea50b99f237fea26b0dd11/aspnetcore/web-api/error-handling.md. All of those versions have the "MVC transforms an error result" paragraph and none of them hides it from ASP.NET Core 2.1.

Rick-Anderson commented 5 years ago

I think this page should do one of:

  • demonstrate how to format ProblemDetails in an RFC 7807 compliant manner on ASP.NET Core 2.1;
  • recommend defining an app-specific type instead of using ProblemDetails, if targeting ASP.NET Core 2.1;
  • recommend upgrading to ASP.NET Core 2.2 or later, if RFC 7807 compliance is desired. (This upgrade may be difficult because ASP.NET Core 2.1 is the last long-time support (LTS) version that can be run on .NET Framework.)

How about this:

recommend upgrading to ASP.NET Core 2.2 or later, if RFC 7807 compliance is desired. If you can't upgrade:

recommend defining an app-specific type instead of using ProblemDetails,

@JamesNK or @pranavkm is that OK? @scottaddie can you schedule this?

cc @serpent5 if you're interested.

pranavkm commented 4 years ago

@KalleOlaviNiemitalo out of the box, the type in 2.1 is compliant with the RFC. The 3 issues while good to have would generally not be considered blocking to use the ProblemDetails type in 2.1.

KalleOlaviNiemitalo commented 4 years ago

16116 does not fix the misinformation that I originally reported:

However, although ASP.NET Core 2.1.12 defines the ProblemDetail type, it never transforms error results to ProblemDetails. That feature was added for ASP.NET Core 2.2, in https://github.com/aspnet/AspNetCore/commit/5bd818bd64641208e52e9350f443d1336f544e41. Please hide the text when ASP.NET Core 2.1 is selected.

Rick-Anderson commented 4 years ago

Moved to #16385