Skip to content

Allow to favor throwing Exceptions instead of swallowing and formatting them directly to Response #886

Closed
@gimlichael

Description

@gimlichael

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe the problem.

So when I was browsing my API using your excellent framework i noticed this "exception":

{
  "type": "https://docs.api-versioning.org/problems#invalid",
  "title": "Invalid API version",
  "status": 400,
  "detail": "The HTTP resource that matches the request URI 'someurl' does not support the API version 'b3'.",
  "Code": "InvalidApiVersion",
  "traceId": "00-fe622aed3e09484395e8cad918cb4df8-78da4931d596fa48-00"
}

Problem is, that this is never thrown as an exception .. you are overtaking the Response pipeline and providing a "friendly" error message.

I would really like to have full control of exception handling - and I strongly believe a framework such as yours, should support this, and not try to take control of the Response pipeline and hereby interfere with expected outcome.

The "exception" is triggered because both Edge and Chrome has an odd version in their default accept header.

Describe the solution you'd like

I hope you will consider allowing throwing exceptions instead of swallowing them and transform them on my behalf.
This should be done while staying true to your intent of not breaking backward compatibility.

In this case, I would expect (by looking at your code) a FormatException which I could choose to ignore or format as I see fit.

It is vital that APIs has full control over exception handling - or in this case, the lack of it.

Additional context

Areas of interest I have found in your code:

https://github.com/dotnet/aspnet-api-versioning/blob/main/src/AspNetCore/WebApi/src/Asp.Versioning.Http/Routing/MalformedApiVersionEndpoint.cs

https://github.com/dotnet/aspnet-api-versioning/blob/main/src/Abstractions/src/Asp.Versioning.Abstractions/ApiVersionParser.cs

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions