Skip to content

Commit 0354fec

Browse files
Add option to configure the status code when a version is unsupported
1 parent 900d9ef commit 0354fec

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

src/Common/src/Common/ApiVersioningOptions.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
namespace Asp.Versioning;
44

55
using Asp.Versioning.Routing;
6+
#if NETFRAMEWORK
7+
using System.Net;
8+
#endif
69
using static Asp.Versioning.ApiVersionReader;
710

811
/// <summary>
@@ -100,4 +103,35 @@ public IApiVersioningPolicyBuilder Policies
100103
get => apiVersioningPolicyBuilder ??= new ApiVersioningPolicyBuilder();
101104
set => apiVersioningPolicyBuilder = value;
102105
}
106+
107+
/// <summary>
108+
/// Gets or sets the HTTP status code used for unsupported versions of an API.
109+
/// </summary>
110+
/// <value>The HTTP status code. The default value is 400 (Bad Request).</value>
111+
/// <remarks>
112+
/// <para>While any HTTP status code can be provided, the following are the most sensible:</para>
113+
/// <list type="table">
114+
/// <listheader>
115+
/// <term>Status</term>
116+
/// <description>Description</description>
117+
/// </listheader>
118+
/// <item>
119+
/// <term>400 (Bad Request)</term>
120+
/// <description>The API doesn't support this version</description>
121+
/// </item>
122+
/// <item>
123+
/// <term>404 (Not Found)</term>
124+
/// <description>The API doesn't exist</description>
125+
/// </item>
126+
/// <item>
127+
/// <term>501 (Not Implemented)</term>
128+
/// <description>The API isn't implemented</description>
129+
/// </item>
130+
/// </list>
131+
/// </remarks>
132+
#if NETFRAMEWORK
133+
public HttpStatusCode UnsupportedApiVersionStatusCode { get; set; } = HttpStatusCode.BadRequest;
134+
#else
135+
public int UnsupportedApiVersionStatusCode { get; set; } = 400;
136+
#endif
103137
}

0 commit comments

Comments
 (0)