diff --git a/modules/swagger-codegen/src/main/resources/csharp/apiInvoker.mustache b/modules/swagger-codegen/src/main/resources/csharp/apiInvoker.mustache index f7c76ee2c56..8b58f23e429 100644 --- a/modules/swagger-codegen/src/main/resources/csharp/apiInvoker.mustache +++ b/modules/swagger-codegen/src/main/resources/csharp/apiInvoker.mustache @@ -120,7 +120,8 @@ try { var webResponse = (HttpWebResponse)client.GetResponse(); - if (webResponse.StatusCode != HttpStatusCode.OK) + int statusCode = (int)webResponse.StatusCode; + if (statusCode / 100 != 2) // non-success status { webResponse.Close(); throw new ApiException((int)webResponse.StatusCode, webResponse.StatusDescription); diff --git a/samples/client/petstore/csharp/src/main/csharp/io/swagger/client/ApiInvoker.cs b/samples/client/petstore/csharp/src/main/csharp/io/swagger/client/ApiInvoker.cs index 736b51b81f9..12cc374bf8d 100644 --- a/samples/client/petstore/csharp/src/main/csharp/io/swagger/client/ApiInvoker.cs +++ b/samples/client/petstore/csharp/src/main/csharp/io/swagger/client/ApiInvoker.cs @@ -120,7 +120,8 @@ private object invokeAPIInternal(string host, string path, string method, bool b try { var webResponse = (HttpWebResponse)client.GetResponse(); - if (webResponse.StatusCode != HttpStatusCode.OK) + int statusCode = (int)webResponse.StatusCode; + if (statusCode / 100 != 2) // non-success status { webResponse.Close(); throw new ApiException((int)webResponse.StatusCode, webResponse.StatusDescription);