autorest
autorest copied to clipboard
(C#) If JSON deserialization fails, the exception should capture the response body
The generated C# code for an operation currently includes a block like this for deserializing the response:
// Deserialize Response
if ((int)statusCode == 200)
{
try
{
string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
result.Body = JsonConvert.DeserializeObject<AdminKeyResult>(responseContent, this.Client.DeserializationSettings);
}
catch (JsonException ex)
{
throw new RestException("Unable to deserialize the response.", ex);
}
}
if (shouldTrace)
{
ServiceClientTracing.Exit(invocationId, result);
}
return result;
Note that if RestException is thrown, the response isn't traced. The value of responseContent should be included in the RestException to help users troubleshoot deserialization failures.
Fixed as part of https://github.com/Azure/autorest/pull/625
Thanks!