dotnet/aspnetcore

Inconsistency between ApiBehaviorOptions.ClientErrorMapping and ReasonPhrases.GetReasonPhrase() using 500

Open

#16,880 建立於 2019年11月6日

在 GitHub 查看
 (10 留言) (0 反應) (0 負責人)C# (37,933 star) (10,653 fork)batch import
affected-very-fewarea-mvcbugfeature-mvc-execution-pipelinehelp wantedseverity-nice-to-have

描述

Asp.net Core 3.0 Windows 10 vs 2019 16.3.7

There was a new 500 status code added to ClientErrorMapping as seen at https://github.com/aspnet/AspNetCore/blob/2e4274cb67c049055e321c18cc9e64562da52dcf/src/Mvc/Mvc.Core/src/DependencyInjection/ApiBehaviorOptionsSetup.cs

options.ClientErrorMapping[500] = new ClientErrorData
            {
                Link = "https://tools.ietf.org/html/rfc7231#section-6.6.1",
                Title = Resources.ApiConventions_Title_500,
            };

The resource file was updated on Aug 5 to include the new ApiConventions_Title_500: https://github.com/aspnet/AspNetCore/commit/709b390157912de0d41b99ec562ed1456d33b6a4#diff-9bdb4982da4faebe331804556c9f3a74

  <data name="ApiConventions_Title_500" xml:space="preserve">
    <value>An error occured while processing your request.</value>
  </data>

That is all well and good but it looks like the ReasonPhrases.GetReasonPhrase() is no longer in sync and so calling ReasonPhrases.GetReasonPhrase(500) still returns Internal Server Error. Isn't this a bug in that it is out of sync?

I saw that it looked like ReasonPhrases was going to get moved but I can't find that it has. Is the issue that I am using an old API and there is a new one that is updated with the new 500 error message?

When running a 2.2 app, ClientErrorMapping does NOT contain a 500 but running as 3.0 as seen below, it does have a 500 error mapping:

public MyClass(IOptions<ApiBehaviorOptions> apiOptions)
        {
            var options = apiOptions.Value;
            var msg = options.ClientErrorMapping[500];
            // msg = "An error occured while processing your request."
        }

My code uses ClientErrorMapping when the mapping is not supressed and I have a test that I used in 2.2 that verifies the Title of a ProblemDetails is the same as the Reason phrase and now the test is failing in 3.0.

Thanks!

貢獻者指南