Skip to content

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

Open
@douggish

Description

@douggish

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

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions