-
Notifications
You must be signed in to change notification settings - Fork 713
API Versioning Error Response in Version =8.1 and Handling Different Default Versions for different Controllers #1125
-
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.