[BUG] Property Body on CloudException is null
See original GitHub issueDescribe the bug The property Body is null on CloudException when the exception is created from a bad request to https://management.azure.com/subscriptions/{subscriptionId}/providers/Microsoft.Network/locations/{location}/usages?{api_version}
I found that the error is happening because the response is an scaped string and not a Json, so the Deserialize throw a JsonException and the Body is never set for that reason.
Exception or Stack Trace
To Reproduce Send a proper request to the endpoint mentioned above with a not supported location in order to get a Bad Request response. Try to parse the Response Content to a CloudError Object Catch the JsonException.
Code Snippet From https://github.com/Azure/azure-sdk-for-net/commit/149dd1b6b4889f5c3b730aa86eaa3e41ec451604 Operation.cs
var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode)); try { _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); CloudError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<CloudError>(_responseContent, Client.DeserializationSettings); if (_errorBody != null) { ex = new CloudException(_errorBody.Message); ex.Body = _errorBody; } } catch (JsonException) { // Ignore the exception }
Expected behavior Get a well formated Json Parse the Json Map to CloudError properly
Screenshots
Setup (please complete the following information):
- OS: Windows 10
- IDE : Visual Studio Professional 2017
- Version of the Library used
Additional context
Information Checklist
- [ X ] Bug Description Added
- [ X ] Repro Steps Added
- [ X ] Setup information Added
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (4 by maintainers)
Top GitHub Comments
Thank you for opening this issue! We are routing it to the appropriate team for follow up.
@leagallino , the issue could not be reproduced and don’t get response for 10 days, so close it. Please feel free to reopen it if you could reproduce it, thanks.