Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTTP 202 C# generated client throws exception #1303

Closed
aaronhudon opened this issue Apr 25, 2018 · 1 comment
Closed

HTTP 202 C# generated client throws exception #1303

aaronhudon opened this issue Apr 25, 2018 · 1 comment

Comments

@aaronhudon
Copy link

Using NSwag.MSBuild 11.17.0

Code generation command:
<Exec Command="$(NSwagExe) swagger2csclient /input:$(ProjectDir)\XXX.swagger.json /output:$(ProjectDir)\XXX.generated.cs /Namespace:XXX /ClientBaseClass:XXX /UseHttpRequestMessageCreationMethod:true /ConfigurationClass:XXX /UseHttpClientCreationMethod:true /GenerateOptionalParameters:true /ClassStyle:Poco" />

The C# generated code for a 202 response always throws an exception. Is this by design? 2xx codes are supposed to be non error.

Generated code looks like:

if (status_ == "202") 
{
	var responseData_ = await response_.Content.ReadAsStringAsync().ConfigureAwait(false); 
	var result_ = default(xxx); 
	try
	{
		result_ = Newtonsoft.Json.JsonConvert.DeserializeObject<xxx>(responseData_, _settings.Value);
	} 
	catch (System.Exception exception_) 
	{
		throw new SwaggerException("Could not deserialize the response body.", (int)response_.StatusCode, responseData_, headers_, exception_);
	}
	throw new SwaggerException<xxx>("A server side error occurred.", (int)response_.StatusCode, responseData_, headers_, result_, null);  // <-- ALWAYS THROWING EXCEPTION
}
@jeremyVignelles
Copy link
Collaborator

Hello,
I think this is a duplicate of #1259 : NSwag needs to understand that 202, 204... are success as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants