API Versioning Error Response in Version =8.1 and Handling Different Default Versions for different Controllers #1125
Unanswered
Mercygoldm
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello,
I am adding API Versioning to my ASP.NET Core with MVC(Core) project. I am using this version of the package
PackageReference Include="Asp.Versioning.Mvc" Version="8.1.0" . I have a a few questions:-
Question 1:
I want to handle the different API versioning errors accordingly (log, throw an exception etc).
services.AddErrorObjects().AddProblemDetails(); - Does this mean process all errors or Process only API version errors?
services.AddErrorObjects() - Does this mean process only API version errors?
I want to only process API versioning errors, since I have other setup in place to handle other errors. Which of these two is the right way to handle only API versioning error? I went over this wiki https://github.com/dotnet/aspnet-api-versioning/wiki/Error-Responses but i did not quite understand this part so I wanted to clarify
Questions 2:
Context
If I have Controller A, B, C and D in the same project
A has versions - 2021-01-01, 2022-02-02 and supports Get ~/A?api-version=2021-01-01, Get ~/A?api-version=2022-01-01, ~/Get
B has version - 2023-03-03 and supports Get ~/B?api-version=2023-03-03 and Get ~/B
C has versions 2024-04-04 and supports Get ~/C?api-version=2024-04-04 and Get ~/C
D has no version
I want to configure Controller A to support requests with api-version and if a request does not have a version specified for it to fall back to 2022-02-02(the latest supported version for A), Controller B to support requests with api-version and if a request does not specify a version for it to fall back on version 2023-03-03 (the latest version for B) and same behaviour for C and exclude Controller D from versioning since it has no any assigned versions. And if request passes a unsupported/Invalid/Ambiguous version for an exception to be throw
I currently have my startup.cs like this
services.AddApiVersioning(
options =>
{
options.AssumeDefaultVersionWhenUnspecified = true;
options.ReportApiVersions = true;
options.ApiVersionReader = new QueryStringApiVersionReader("api-version");
}).AddMvc();
Question:
2a. what is the best way to handle the fall back behaviour given that each controller falls back to a different version name when unspecified?
2b. How can i exclude controller D from API versioning?
I did try using [ApiVersionNeutral] and options.AssumeDefaultVersionWhenUnspecified = true; but this weird behaviour was happening so I thought I should clarify on this before proceeding
Beta Was this translation helpful? Give feedback.
All reactions