dotnet/aspnetcore

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

Fermée

#16 880 ouverte le 6 nov. 2019

 (10 commentaires) (0 réaction) (0 personne assignée)C# (10 653 forks)batch import
affected-very-fewarea-mvcbugfeature-mvc-execution-pipelinehelp wantedseverity-nice-to-have

Métriques du dépôt

Stars
 (37 933 étoiles)
Métriques de merge PR
 (Merge moyen 16j 9h) (258 PRs mergées en 30 j)

Description

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!

Guide contributeur