Skip to content

Bug: StatusCode 400 instead of 404 on valid version with parameter constraint violation #105

Closed
@codepunkt

Description

@codepunkt

The following example is reduced to its bare minimum. I have enabled URL-Path versioning for ASP.Net Web API according to the documentation in the Wiki:

this.config.MapHttpAttributeRoutes(new DefaultInlineConstraintResolver()
{
    ConstraintMap =
    {
        ["apiVersion"] = typeof(ApiVersionRouteConstraint)
    }
});
this.config.AddApiVersioning();

Controller is defined like this:

[ApiVersion("1.0")]
[RoutePrefix("api/v{version:apiVersion}/resource")]
public class ResourceController : ApiController
{
    [HttpGet]
    [Route("{id:int}")]
    public async Task<IHttpActionResult> Get([FromUri] int id)
    {
        return Ok();
    }

    [HttpDelete]
    [Route("{id}")]
    public async Task<IHttpActionResult> Delete(int id)
    {
        return Ok();
    }
}

What happens is this:

  • GET-request to api/v1/resource/123 → server responds with 200 OK.
  • GET-request to api/v2/resource/123 → server responds with 400 Bad Request, including the standard error response with error code UnsupportedApiVersion as described in the documentation wiki
  • GET-request to api/v1/resource/asdf → server responds with 400 Bad Request, including UnsupportedApiVersion just as the previous example.

This seems wrong. The given URL would never match a route when GET-requested.

When i add the :int constraint to the DELETE route or remove the route altogether, the GET-request to api/v1/resource/asdf returns 404 Not Found with an empty body as expected.

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions