autorest
autorest copied to clipboard
[C# Client Runtime] Non-JSON error responses cause JsonReaderExceptions
In AzureClientExtensions.cs, we try to handle non-success response status codes by deserializing the response content into a CloudError object. The expected behavior is to throw a new CloudException, which can be caught and inspected for the request/response/responseBody. However, if the server does not return a JSON response (e.g. the default IIS error response is XML), then this deserialization fails (see the call to DeserializeObject<CloudError>), throwing an unexpected JsonReaderException.
The correct behavior would be to still throw a CloudException, even if we can't deserialize responseContent.