autorest
autorest copied to clipboard
Suggestion: Don't throw an exception if the http status code is 2xx
Currently this is the generated client code for every request:
if (!(statusCode == (HttpStatusCode)Enum.Parse(typeof(HttpStatusCode), "OK")))
{
var ex = new HttpOperationException(string.Format("Operation returned an invalid status code '{0}'", statusCode));
ex.Request = httpRequest;
ex.Response = httpResponse;
if (shouldTrace)
{
ServiceClientTracing.Error(invocationId, ex);
}
throw ex;
}
This means if I return http status code "201 created" that an exception will be thrown, when all 2xx codes indicate success.
Should this be changed to anything from >= 300?
You can control this by modifying the responses in your Swagger spec. For example:
"responses": {
"200": {
"description": "",
"schema": {
"$ref": "#/definitions/DataSource"
}
},
"201": {
"description": "",
"schema": {
"$ref": "#/definitions/DataSource"
}
}
Ah great didn't see this, cheers!
I found a good article on doing this here: https://azure.microsoft.com/en-us/documentation/articles/app-service-api-dotnet-swashbuckle-customize/