autorest icon indicating copy to clipboard operation
autorest copied to clipboard

[C# Client Runtime] Non-JSON error responses cause JsonReaderExceptions

Open tbombach opened this issue 10 years ago • 0 comments

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.

tbombach avatar Apr 13 '16 20:04 tbombach