Microsoft.Azure.Documents.ServiceUnavailableException is internal to Microsoft.Azure.Cosmos.Direct
See original GitHub issueIs your feature request related to a problem? Please describe. We have the need to track when Microsoft.Azure.Documents.ServiceUnavailableException exceptions are thrown by the Cosmos DB SDK. Unfortunately it and its parent class, Microsoft.Azure.Documents.DocumentClientException, are internal to the Microsoft.Azure.Cosmos.Direct assembly. Furthermore, we really want to track the sub status code on the ServiceUnavailableException but the sub status code is a field on DocumentClientException and the Microsoft.Azure.Documents.SubStatusCodes enumeration is also internal to the Microsoft.Azure.Cosmos.Direct assembly.
Describe the solution you’d like Is it possible to make ServiceUnavailableException, DocumentClientException, and SubStatusCodes public types while also making the sub status code on DocumentClientException a public property?
Describe alternatives you’ve considered To get around this, we have to catch a plain Exception then use reflection to identify the exception as a ServiceUnavailableException then get its sub status code.
try
{
// ...
}
catch (Exception ex)
{
var cosmosDirectAssembly = Assembly.Load("Microsoft.Azure.Cosmos.Direct");
var typeOfServiceUnavailableException = cosmosDirectAssembly.GetType("Microsoft.Azure.Documents.ServiceUnavailableException", false);
var typeOfCosmosSubStatusCodes = cosmosDirectAssembly.GetType("Microsoft.Azure.Documents.SubStatusCodes", false);
var typeOfNullableCosmosSubStatusCodes = typeof(Nullable<>).MakeGenericType(typeOfCosmosSubStatusCodes);
var typeOfDocumentClientException = cosmosDirectAssembly.GetType("Microsoft.Azure.Documents.DocumentClientException", false);
var serviceUnavailableExceptionSubStatusCode = typeOfDocumentClientException
.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
.FirstOrDefault(p => p.FieldType == typeOfNullableCosmosSubStatusCodes);
if (ex.GetType() == typeOfServiceUnavailableException)
{
var subStatusCode = serviceUnavailableExceptionSubStatusCode.GetValue(ex);
// Log the substatus code
}
}
Issue Analytics
- State:
- Created 8 months ago
- Reactions:1
- Comments:5 (3 by maintainers)
Top GitHub Comments
I want to reiterate, if the use case is there, we will help either making the information accessible through public methods or properties if it’s not or helping with how you can obtain it from the current public methods. But there should be a use case for it, there should be value in exposing that.
Everything described in this thread so far is achievable through the current public surface API.
@ealsur
GoneException::LocalIp
or one of theDocumentClientException
properties that aren’t exposed on theCosmosException
(e.g.StatusDescription
).CosmosException::SubStatusCode
. As you mentioned, the issue is acting upon it programmatically, namely comparing the substatus to some known values in the currentlyinternal
enumSubStatusCodes
. I imagine there might be various use cases, but if I were to speak to ours, it’s for detecting client-side issues specifically (e.g.TimeoutGenerated410
). For example, we might to translate these into other HTTP responses back to the original caller (e.g. 429).