Skip to content
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

The error 'code' is not included in the error response when using AddErrorObjects() #1091

Open
1 task done
douggish opened this issue May 21, 2024 · 2 comments
Open
1 task done
Assignees
Labels

Comments

@douggish
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

When using Microsoft.AspNetCore.Mvc.Versioning 5.1.0, the error responses contained an error code (e.g. ApiVersionUnspecified). When upgrading to Asp.Versioning 8.1.0, the documentation states that it is possible to retain the previous "Error Object" format (which I would expect to include the code property). However, even when using builder.Services.AddErrorObjects().AddProblemDetails(), there is no code property in the error response.

I'm seeing something like this:

{
    "error": {
        "message": "Unspecified API version",
        "target": "Unspecified API version",
        "innerError": {
            "message": "An API version is required, but was not specified."
        }
    }
}

Expected Behavior

I expected the error response to match what is was in the older version (especially the code property):

{
  "error": {
    "code": "ApiVersionUnspecified",
    "message": "An API version is required, but was not specified.",
    "innerError": null
  }
}

Steps To Reproduce

No response

Exceptions (if any)

No response

.NET Version

8.0.204

Anything else?

I think this line of code is perhaps missing a not:
https://github.com/dotnet/aspnet-api-versioning/blob/main/src/AspNetCore/WebApi/src/Asp.Versioning.Http/Routing/EndpointProblem.cs#L28

@commonsensesoftware
Copy link
Collaborator

Yeah, it looks like this is meant to be:

+if ( !string.IsNullOrEmpty( code ) )

😳 doh!

@commonsensesoftware
Copy link
Collaborator

I'll work on getting out a fix. CRs are also welcome. 😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants